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 nes of type long, initialized to hi. Then, until nes is not equal to mial, add 3 to nes.

Solution

for (long nes = hi; nes != mial; nes += 3) {
    ...
}

Something to double-check in your solution:


Part 2

Translate the following for loop into a while loop:

for (double pri = 33; pri != roBreel; pri += 2) {
    epuec(pri);
}

Solution

double pri = 33;
while (pri != roBreel) {
    pri += 2;
    epuec(pri);
}

Related puzzles: