Translate the following natural language description of a loop into a for loop:
Declare a variable namednaof typedouble, initialized toii. Then, untilnais less than or equal tococ, dividenaby4.
for (double na = ii; na < coc; na /= 4) {
...
}
Something to double-check in your solution:
na < coc)?Consider the following code:
A while (B) { C if (D) { E F break; } G H } I
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.
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 G H I
Order:
A B C D E F G H B C D E F G H B C G H I
Translate the following while loop into a for loop:
long el = ec;
while (el >= floin) {
el *= 2;
pner();
pioust(el);
}
for (long el = ec; el >= floin; el *= 2) {
pioust(el);
pner();
}
Related puzzles: