M4ritimeSeeker

Kahoot Questions and Answers: Spring 2022 Loops

Feb 23rd, 2022 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. 1) What type of loop is this?
  2.  
  3. int i = 0;
  4. do
  5. {
  6. printf("%d", i);
  7. i--;
  8. } while(i > 0);
  9.  
  10. ANSWERS: Posttest, Do-While
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. 2) What type of loop is this?
  22.  
  23. int i - 9;
  24. while(i > 0)
  25. {
  26. printf("%d", i);
  27. i--;
  28. }
  29.  
  30. ANSWERS: Pretest, While
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. 3) What does a loop need to avoid looping infinitely?
  40.  
  41. ANSWER: An update
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. 4) When would you use a 'for' loop
  53.  
  54. ANSWER: If you know EXACTLY how many times it will loop
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. 5) Which of the following is the ITERATOR?
  64.  
  65. int i = 0;
  66. while(i > 0)
  67. {
  68. printf("%d", i);
  69. i--;
  70. }
  71.  
  72. ANSWER: int i
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. 6) All loops need an update or break or else they will be infinite
  83.  
  84. ANSWER: True
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. 7) Which of the following is the TEST CONDITION?
  94.  
  95. int i = 0;
  96. while(i > 0)
  97. {
  98. printf("%d", i);
  99. i--;
  100. }
  101.  
  102. ANSWER: i > 0
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115. 8) 'for( ; ; )' is a legal loop and will end at some point.
  116.  
  117. ANSWER: False
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. 9) Does 'break' work in a loop?
  132.  
  133. ANSWER: Yes
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. 10) What is wrong with this loop?
  144.  
  145. int i;
  146. for (i = 0; i < 10; i++); {
  147. printf("%d\n", i);
  148. }
  149.  
  150. ANSWER: Extra Semi-Colon
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. 11) This program is supposed to print 0 thorugh 10. WHERE is the error?
  159.  
  160. int i;
  161. for ( i = 0; i > 10; i++ ) {
  162. printf("%d\n", i);
  163. }
  164.  
  165. ANSWER: The condition i > 10.
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. 12) What is wrong with this loop?
  174.  
  175. int i;
  176. while (i < 10) {
  177. printf("%d\n", i);
  178. }
  179.  
  180. ANSWER: Missing increment
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189. 13) What THREE things does ANY loop need to be complete?
  190.  
  191. An iterator variable, a test condition, and an increment (also known as an update).
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
Add Comment
Please, Sign In to add comment