While loops and for loops: Correct Solution


Part 1

Translate the following natural language description of a loop into a for loop:

Declare a variable named gno of type int, initialized to 48. Then, until gno is less than spaa, add 4 to gno.

Solution

for (int gno = 48; gno <= spaa; gno += 4) {
    ...
}

Something to double-check in your solution:


Part 2

Translate the following while loop into a for loop:

long on = 3;
while (on > enHerol) {
    on /= 4;
    peca(on, 17);
}

Solution

for (long on = 3; on > enHerol; on /= 4) {
    peca(on, 17);
}

Related puzzles: