Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) What type of loop is this?
- int i = 0;
- do
- {
- printf("%d", i);
- i--;
- } while(i > 0);
- ANSWERS: Posttest, Do-While
- 2) What type of loop is this?
- int i - 9;
- while(i > 0)
- {
- printf("%d", i);
- i--;
- }
- ANSWERS: Pretest, While
- 3) What does a loop need to avoid looping infinitely?
- ANSWER: An update
- 4) When would you use a 'for' loop
- ANSWER: If you know EXACTLY how many times it will loop
- 5) Which of the following is the ITERATOR?
- int i = 0;
- while(i > 0)
- {
- printf("%d", i);
- i--;
- }
- ANSWER: int i
- 6) All loops need an update or break or else they will be infinite
- ANSWER: True
- 7) Which of the following is the TEST CONDITION?
- int i = 0;
- while(i > 0)
- {
- printf("%d", i);
- i--;
- }
- ANSWER: i > 0
- 8) 'for( ; ; )' is a legal loop and will end at some point.
- ANSWER: False
- 9) Does 'break' work in a loop?
- ANSWER: Yes
- 10) What is wrong with this loop?
- int i;
- for (i = 0; i < 10; i++); {
- printf("%d\n", i);
- }
- ANSWER: Extra Semi-Colon
- 11) This program is supposed to print 0 thorugh 10. WHERE is the error?
- int i;
- for ( i = 0; i > 10; i++ ) {
- printf("%d\n", i);
- }
- ANSWER: The condition i > 10.
- 12) What is wrong with this loop?
- int i;
- while (i < 10) {
- printf("%d\n", i);
- }
- ANSWER: Missing increment
- 13) What THREE things does ANY loop need to be complete?
- An iterator variable, a test condition, and an increment (also known as an update).
Add Comment
Please, Sign In to add comment