Presentation is loading. Please wait.

Presentation is loading. Please wait.

For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n.

Similar presentations


Presentation on theme: "For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n."— Presentation transcript:

1 For Next Looping My first Looping Structure

2 For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n NEXT counter_variable

3 For…Next

4 For…Next You use For...Next statements to execute a block of statements a specific number of times. For loops use a counter variable whose value is increased or decreased with each repetition of the loop.

5 For…Next Part of the structure Index or counter Starting value Ending value Next (increments counter) Iteration (one execution of the statement inside the loop)

6 Action of For...Next structure Deterministic loop For i = start To end statement1 statement2... I <=ending value i >ending value Next (i) For i = start To end statement1 statement2... Next (i) statement Increment counter Here

7 For Next Loops deterministic Repeats a statement OR a group of statements a specified number of times Dim intStoreNumber As Integer For intStoreNumber = 1 To 20 ' Check the order ' Fetch correct order ' Carry back Stales Next intStoreNumber

8 For…Next with Step Dim intStoreNumber As Integer For intStoreNumber = 1 To 19 Step 2 ' Check the order ' Fetch correct order ' Carry back empties Print intStoreNumber Next (increments counter by the step) How many times will this loop execute?

9 Simple loop Dim x as integer, _ var1 as string, _ var2 as string, _ var3 as string For x = 1 To 50 input #1, var1,var2,var3 Call PrintData(var1,var2) Next x

10 Step Increments You can increase or decrease the counter variable by a value other than 1 by using the Step keyword. Example Dim intCounter as integer, _ intTotal as integer For intCounter = 2 To 10 Step 2 intTotal = intTotal + intCounter Next intCounter Is intTotal a counter or accumulator?

11 Nesting: What is the Outcome Dim Outer as integer, Inner as integer For Outer = 1 To 8 Print Outer; For Inner = 1 To Outer Print "X "; Next Inner Print Next Outer

12 Outcome of the loop 1 X 2 XX 3 XXX 4 XXXX 5 XXXXX 6 XXXXXX 7 XXXXXXX 8 XXXXXXXX


Download ppt "For Next Looping My first Looping Structure. For…Next FOR counter_variable = initial_value TO end_value STEP increment Statement-1 Statement-2 ……. Statement-n."

Similar presentations


Ads by Google