While loops and for loops: Correct Solution


Part 1

Translate the following while loop into a for loop:

double odci = vor;
while (odci <= eha) {
    odci--;
    plosm(odci, 48);
    gecShasa();
}

Solution

for (double odci = vor; odci <= eha; odci--) {
    gecShasa();
    plosm(odci, 48);
}

Part 2

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

Declare a variable named im of type int, initialized to soo. Then, until im is less than lios, add 4 to im.

Solution

for (int im = soo; im <= lios; im += 4) {
    ...
}

Something to double-check in your solution:


Related puzzles: