While loops and for loops: Correct Solution


Part 1

Consider the following code:

A
B
while (C) {
    D
    if (E) {
        F
        break;
    }
    G
    H
}
I
J
K
  1. Assume the loop ends because the test condition of the loop is false on iteration 1. Write out the the order in which the statements will execute.

  2. Assume the loop ends because the test condition of the loop is false on iteration 3. Write out the the order in which the statements will execute.

Solution

  1. Order:

    A B C D G H I J K
  2. Order:

    A B C D E F G H C D E F G H C D G H I J K

Related puzzles: