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 sce of type int, initialized to 60. Then, until sce is less than or equal to pioc, add 4 to sce.

Solution

for (int sce = 60; sce < pioc; sce += 4) {
    ...
}

Something to double-check in your solution:


Part 2

Translate the following for loop into a while loop:

for (int puso = cles; puso != cuou; puso--) {
    clist(puso, 48);
}

Solution

int puso = cles;
while (puso != cuou) {
    puso--;
    clist(puso, 48);
}

Related puzzles: