Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1).When should a programmer select a for loop for his or her program? A. When he

ID: 3558186 • Letter: 1

Question

1).When should a programmer select a for loop for his or her program?

      A. When he or she knows the exact number of times the loop will be executed.

      B. When he or she is not sure how many times the loop will be executed.

      C. When he or she knows the loop must be executed at least once.

      D. There is no reason to select a for loop. Any loop can be used any time.

2). When should a programmer select a do while loop for his or her program?

      A. When he or she knows the exact number of times the loop will be executed.

      B. When he or she is not sure how many times the loop will be executed.

      C. When he or she knows the loop must be executed at least once.

      D. There is no reason to select a do while loop. Any loop can be used any time.

3). When should a programmer select a while loop for his or her program?

      A. When he or she knows the exact number of times the loop will be executed.

      B. When he or she is not sure how many times the loop will be executed.

      C. When he or she knows the loop must be executed at least once.

      D. There is no reason to select a while loop. Any loop can be used any time.

4). In this while loop statement, while(counter < 10)

the variable counter is an int. Which statement below is an

     equivalent way to write this while statement?

      A. while(10 > counter)

      B. while( counter <= 9)

      C. while(9 > counter)

      D. A and B are correct

5). How many times will this for loop execute? (Note: i is an int.)

        for(i = 0; i < 10; ++i)

      A. 0, the loop will not execute

      B. 9

      C. 10

      D. The loop is not written correctly. It would not compile.

6). How many times will this for loop execute? (Note: i is an int.)

       for(i = 0; i > 100; ++i)

      A. 0, the loop will not execute

      B. 99

      C. 100

      D. The loop is not written correctly. It would not compile.

7). How many times will this for loop execute? (Note: i is an int.)

      for(i = 100; i > 0; --i)

      A. 0, the loop will not execute

      B. 99

      C. 100

      D. The loop is not written correctly. It would not compile.

8). How many times will this for loop execute? (Note: i is an int.)

         for(i = 0; i < 10; --i)

      A. 0, the loop will not execute

      B. 9

      C. 10

      D. It is an infinite loop.

9). Why are break statements needed inside a switch

Explanation / Answer

1)   A. When he or she knows the exact number of times the loop will be executed.

2)     C. When he or she knows the loop must be executed at least once.

3) B. When he or she is not sure how many times the loop will be executed.

4)    D. A and B are correct

5) C. 10

6)    A 0, the loop will not execute

7) C. 100

8)   D. It is an infinite loop.

9)    A. The break statements cause the program to jump out of the switch.

10)   B. switch, case, break, default

11)    if (user_input == 0 || 1)

the if statement is not wriiten correctly it should written as

if (user_input == 0 || user_input == 1)

12) In each case statement there is no break so by adding break will eliminate the problem

case 1:

      cout <<