next up previous
Next: continue Statement Up: while Loop Previous: do-while Loop

Activity

1.
What does the next program part write:
  for (i=2; i<5; i++) cout << i;
2.
What does the next program part write:
    for (i=2; i<5; i++); cout << i;

3.
What does the next program part write:
    for (i=2; i<5; i=i+2) cout << i;

4.
What does the next program part write:
    for (i=2; i<5; i=i+3) cout << i;

5.
What does the next program part write:
    for (i=5; i<5; i=i+3) cout << i;

6.
How many exclamation marks does the next program part write:
    for (i=2; i<5; i--) cout << "!";

7.
What does the next program part write:
    for (i=2; i>0; i--) cout << i;

8.
Can you leave the initialization, test, and increment away from a for loop? If so, what would happen?

9.
What is the result of i=0;while (i<2) cout << i++;?

10.
What is the result of while (1==1) cout << '!';?

11.
What is the result of while (1) cout << '!';?

12.
What is the result of while (0) cout << '!';?



Yousef Haik
2/23/1998