While loops and for loops: Correct Solution


Part 1

Translate the following while loop into a for loop:

double clil = 32;
while (clil >= ili) {
    clil++;
    eshpem();
    tasmmo(clil, 43);
}

Solution

for (double clil = 32; clil >= ili; clil++) {
    tasmmo(clil, 43);
    eshpem();
}

Part 2

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

Declare a variable named phou of type int, initialized to plas. Then, until phou is greater than or equal to plo, increment phou.

Solution

for (int phou = plas; phou > plo; phou++) {
    ...
}

Something to double-check in your solution:


Related puzzles: