While loops and for loops: Correct Solution


Part 1

Translate the following while loop into a for loop:

int maur = 9;
while (maur >= suHial) {
    maur++;
    pher(maur, 18);
}

Solution

for (int maur = 9; maur >= suHial; maur++) {
    pher(maur, 18);
}

Part 2

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

Declare a variable named huho of type int, initialized to 36. Then, until huho is less than or equal to heCin, subtract 4 from huho.

Solution

for (int huho = 36; huho < heCin; huho -= 4) {
    ...
}

Something to double-check in your solution:


Related puzzles: