Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011.

Similar presentations


Presentation on theme: "Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011."— Presentation transcript:

1 Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011

2  Definition: Do While condition statement1 statement2 … Loop Example: Do While x<10 a=a+1 b=a+5 x =x+2 Loop

3  Definition: Do statement1 statement2 … Loop Until condition Example: Do a=a+1 b=a+5 x =x+2 Loop Until x >10

4  Definition For var =initVal To finalVal statement1 statement2 … Next Example For x=1 to 5 a =a+1 b=a+5 Next

5  Used when the number of times the loop must be executes is known beforehand  The control variable is initialized and then automatically changes its value after each iteration of the loop  It is a PRETEST kind of loop like Do While Loop  The value of the control variable is incremented by 1 each step.  The value of the control variable should not be altered within the body of the loop  Continue For and Continue Do skips an iteration in a For and, respectively, Do loop  Exit For and Exit Do backs out of a For and, respectively, Do loop

6  Definition For var =initValue To finalValue Step s statement1 statement2 Next Example For i=5 To 10 Step 2 x =x+1 Next NOTE: step can have a negative value

7  1. Counters  2. Accumulators  3. Flags  4. Peek Method

8  A numeric variable that keeps track of the numbers of items that have been processed  Used when we need to execute a loop only for a portion of data.  Ex: ◦ read the first 5 names from the file names.txt ◦ determine how many different type of coins one has

9  Is a numeric variables that total numbers  Used when we need to keep a total of all numbers read  Ex: add all numbers from a file and return this sum

10  Is a variable that keeps track of weather a certain situation has occurred  The data type most suitable for flags is the Boolean data type  Ex: ◦ read all the numbers from a file. If you read a negative number make an error message box that says: “You shouldn’t have negative numbers in the file.”

11  Used to check if we have reached the end of the file  Used with Do While and Do Until loops  This function return the ASCII value of the first character of the line about to be read  If the end of the file has been reached, this function returns -1


Download ppt "Chapter 6: Sections 6.2, 6.3 Roxana Gheorghiu Friday, April 1, 2011."

Similar presentations


Ads by Google