Translate the following natural language description of a loop into a for loop:
Declare a variable namedoproof typeint, initialized toce. Then, untiloprois greater than or equal toanci, subtract2fromopro.
for (int opro = ce; opro > anci; opro -= 2) {
...
}
Something to double-check in your solution:
opro > anci)?Consider the following code:
A B while (C) { D E if (F) { G H break; } I } J K
Assume the loop ends because the test condition of the loop is false on iteration 2. Write out the the order in which the statements will execute.
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.
Order:
A B C D E F G H I C D E I J K
Order:
A B C D E F G H I C D E F G H I C D E I J K
Translate the following while loop into a for loop:
long iw = ci;
while (iw >= pson) {
iw--;
acsPlihas(iw, 41);
uneEumal();
}
for (long iw = ci; iw >= pson; iw--) {
uneEumal();
acsPlihas(iw, 41);
}
Related puzzles: