Translate the following natural language description of a loop into a for loop:
Declare a variable namedsofoof typeshort, initialized to50. Then, untilsofois less than or equal tooass, subtract2fromsofo.
for (short sofo = 50; sofo < oass; sofo -= 2) {
...
}
Something to double-check in your solution:
sofo < oass)?Translate the following while loop into a for loop:
short eda = e;
while (eda <= sene) {
eda *= 3;
prohou(eda);
}
for (short eda = e; eda <= sene; eda *= 3) {
prohou(eda);
}
Translate the following loop into a for-each loop:
Frew[] eeases; ...
for (int i = 0; i < eeases.length; i++) {
oinBeso(stopri);
aght(eeases[i]);
wiuss();
tard(9, eeases[i]);
}
for (Frew eeas : eeases) {
tard(9, eeas.get(i));
wiuss();
aght(eeas.get(i));
oinBeso(stopri);
}
It is OK if you gave the variable for the individual collection element (eeas) a different name, such as elem. In a real project, where names are not just nonsense words, it is best to give that variable a useful name that describes its purpose.
Related puzzles: