While loops and for loops: Correct Solution


Part 1

Translate the following for loop into a while loop:

for (double he = en; he >= aibad; he += 2) {
    enang(he, 41);
}

Solution

double he = en;
while (he >= aibad) {
    he += 2;
    enang(he, 41);
}

Part 2

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

Declare a variable named nac of type int, initialized to 76. Then, until nac is less than eap, increment nac.

Solution

for (int nac = 76; nac <= eap; nac++) {
    ...
}

Something to double-check in your solution:


Related puzzles: