Workshop


Quiz

1.

True or False: Conditional control structures alter the control flow of a program.

2.

If we wanted to print out a message five times if the current hour was past 12, what control structures would we need to use?

3.

Is the following For ... Next loop an example of an infinite loop?

Dim i as Integer For i = 10 to 20 STEP 1   ' Instructions Next i 


4.

True or False: Functions and subroutines must always have at least one input parameter.

Answers

1.

True. Computer programs execute sequentially by default; however, control structures allow for more flexible control flow scenarios.

2.

We'd need to use two controls structures: a conditional control structure to evaluate if the hour is past 12 and a looping control structure to output the message five times. The code for this could look like so:

Dim i as Integer If DateTime.Now.Hour = 12 then   For i = 1 to 5     LabelWebControl.Text &= "This is my message to you.<br>"   Next i End If 


3.

Yes. It is an infinite loop because, at each loop iteration, the looping variable is decreased by 1 (due to the STEP 1). Therefore, the looping variable, which starts at 10, will never reach the loop termination value, 20. This means that this loop is an infinite loop and will run forever.

4.

False. Subroutines and functions can have zero or more input parameters. It is not required that they have more than zero.

Exercises

  1. A common mathematical function is the factorial function. The factorial function takes an integer input n that is greater than or equal to 1, and computes n * (n-1) * ... * 2 * 1. In mathematical texts, factorial is denoted with an exclamation point, as in n!.

    For this exercise, write a function called Factorial() that takes a single Integer input and returns an Integer corresponding to the factorial of the inputted parameter. To help get you started, your function will look like this:

    Function Factorial(n as Integer) as Integer   ' Write code here to compute n!   ' Return the value n! End Function 

    Note that:

    1! = 1 2! = 2 * 1 = 2 3! = 3 * 2 * 1 = 6 4! = 4 * 3 * 2 * 1 = 24 5! = 5 * 4 * 3 * 2 * 1 = 120 

    After you have written this Factorial() function, add a Page_Load event handler that calls the function, displaying on the ASP.NET web page the values of 1! through 5!.

    Hint: The Factorial() function will need to contain a looping construct from 1 to n, where, at each iteration, a variable is multiplied by the value of the looping variable.




Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net