Computer Science I

b. While Loops c. Do/While Loops d. For Loops. ✓ General form of a for loop. ✓ Examples of for loops ... General form of a for loop. ➢ (Fun?) facts about for loops ... on the body. → this is legal syntax but not necessarily good programming!
249KB taille 3 téléchargements 407 vues
Computer Science I CS 135 6. Repetition: While and For Loops a. Repetition Structures b. While Loops c. Do/While Loops d. For Loops 9 General form of a for loop 9 Examples of for loops 9 Nested for loops

10/17-19/2005

CS 135 - Computer Science I - 6. Repetition: While and For Loops

28

6.d For Loops General form of a for loop

¾ General flowchart of a for loop 9 compared to a while loop, a for loop additionally contains an initial statement and an update statement

10/17-19/2005

CS 135 - Computer Science I - 6. Repetition: While and For Loops

29

6.d For Loops General form of a for loop

¾ General syntax of a for loop 1

2

exit

4

for (i = 0; i < 10; i++) { ... cout num; sum += num;

// prompt and increment sum 4 times for (counter = 0; counter < 4; counter++) { cout > num; sum += num;

counter++; }

counter++; }

// display result cout