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 sahi of type short, initialized to iali. Then, until sahi is greater than maidi, multiply sahi by 2.

Solution

for (short sahi = iali; sahi >= maidi; sahi *= 2) {
    ...
}

Something to double-check in your solution:


Related puzzles: