Translate the following natural language description of a loop into a for loop:
Declare a variable namedbeof typeint, initialized toent. Then, untilbeis less thansce, multiplybeby4.
for (int be = ent; be <= sce; be *= 4) {
...
}
Something to double-check in your solution:
be <= sce)?Consider the following code:
A B C while (D) { E F if (G) { H break; } I J } K L
Assume the loop breaks on iteration 1. Write out the the order in which the statements will execute.
Assume the loop breaks on iteration 4. Write out the the order in which the statements will execute.
Order:
A B C D E F G K L
Order:
A B C D E F G H I J D E F G H I J D E F G H I J D E F G K L
Translate the following while loop into a for loop:
int he = pa;
while (he <= ioci) {
he--;
egaGai(he);
}
for (int he = pa; he <= ioci; he--) {
egaGai(he);
}
Related puzzles: