While loops and for loops: Correct Solution


Part 1

Translate the following for loop into a while loop:

for (int eaca = stic; eaca < enAr; eaca *= 4) {
    alblu(eaca);
}

Solution

int eaca = stic;
while (eaca < enAr) {
    eaca *= 4;
    alblu(eaca);
}

Part 2

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

Declare a variable named ho of type double, initialized to 28. Then, until ho is less than or equal to olist, divide ho by 3.

Solution

for (double ho = 28; ho < olist; ho /= 3) {
    ...
}

Something to double-check in your solution:


Related puzzles: