2 Forms of the Repetition Structure For Next loopsCount controlledDo While loopsCondition controlled
3 For Next LoopsTells the computer to repeat one or more statements a specified number of times. Called a pretest loop because the loop is evaluated before the instructions are processed.For loops are used to repeat actions a predetermined number of times.
4 For Next Loop TasksThe loop initializes the counter (often called the index) variable to the startvalue (done only once, at the beginning of the loop).If the stepvalue is positive, the loop tests if the value in counter is greater than the endvalue (when negative the test is less than). If it is, the loop stops; otherwise the instructions within the loop are processed.The loop increments the counter by the stepvalue. It then tests the condition again.
5 For Loop in VLThe for loop element displays the loop variable, initial value, final value, and step by value if it is something other than 1
6 Nested LoopsFor loops allow code inside the body of the loop to be repeated many times.A nested loop refers to a loop contained inside the body of another loop.
7 Nested For LoopsFor each time through the outer loop, the inner loop executes from initial to final by step times.
10 Do While LoopsDo While loops are used when an action is to be repeated an unknown number of times.A pre-test loop tests the looping condition before executing the body of the loop. The body of the loop may not be executed.A post-test loop guarantees at least one execution of the loop body regardless of the condition. The test is after the body of the loop.
11 Pre-test loop Note: This loop may or may not be executed at all True Do It?FalseNote: This loop may ormay not be executed at all
12 Post-test Loop Note: This loop will be executed at least once True Again?FalseNote: This loop will be executed at least once
13 Sentinel ValueA sentinel value (or signaling value) is used to indicate the end of input.The solution flowchart in Figure 3-13 shows -1 as the sentinel value which is checked twice (if and while).
15 Counters and Accumulators Used within a repetition structure to calculate subtotals, totals, and averagesInitialized (usually to 0 or 1) outside the loop and updated within the loopA counter is a numeric variable used for counting something and is updated by 1An accumulator is a numeric variable used for accumulating (adding together) and is updated by an amount that varies
16 Counters and Accumulators Counters are variables that keep track of how many times a statement has executed.Counter = Counter + 1Accumulators are variables that maintain a running total.Accumulator = Accumulator + NewValue
18 Endless LoopsWhen writing loops you must be sure that the condition will terminate the loop or you have what is called an endless or infinite loop.When you write a loop you must be careful to increment the variable or input a new value inside the loop so it will terminate.