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 tac of type int, initialized to nish. Then, until tac is greater than or equal to famoc, decrement tac.

Solution

for (int tac = nish; tac > famoc; tac--) {
    ...
}

Something to double-check in your solution:


Part 2

Translate the following while loop into a for loop:

double co = blic;
while (co != ooa) {
    co *= 2;
    pioism();
    tossbi(co, 22);
}

Solution

for (double co = blic; co != ooa; co *= 2) {
    tossbi(co, 22);
    pioism();
}

Related puzzles: