| Contact PSVM (Q & A) | Notes Below Audio | [toc] [prev] Slide 5 of 12 [next] |
|
|
| 1, 2, 3, 4, [5 (top)], 6, 7, 8, 9, 10, 11, 12, [Lab] |
|
Notes for Slide 05 When using a for-statement to look at each element of an array, the counter variable starts at zero and the loop will end when the counter variable is no longer less than the total number of elements. Recall that the final element of an array is referenced by using the total number of elements minus one. The ++ at the end specifies that the loop counter variable will increment by one each time through the loop. Thus, the variable named counter will start at 0 and then after running statements (that are likely to use the counter variable) the loop will run again with the value of 1 in counter variable. The value in the counter variable then increases to 2, 3, 4, etc. up to the value of 9. The next time the counter variable increments by one it will have the value of 10 which causes the loop to end. After the loop ends, the counter variable is no longer available. 1, 2, 3, 4, [5 (top)], 6, 7, 8, 9, 10, 11, 12, [Lab] |