Translate the following natural language description of a loop into a for loop:
Declare a variable namednalof typeint, initialized togi. Then, untilnalis less thanbetoc, incrementnal.
for (int nal = gi; nal <= betoc; nal++) {
...
}
Something to double-check in your solution:
nal <= betoc)?Translate the following for loop into a while loop:
for (int ed = phid; ed <= coic; ed *= 3) {
lonSwist();
illtit(ed);
}
int ed = phid;
while (ed <= coic) {
ed *= 3;
illtit(ed);
lonSwist();
}
Translate the following loop into a for-each loop:
List<Riccuck> weras; ...
for (int i = 0; i < weras.size(); i++) {
weras.get(i).menhou(spiBosi, suou);
haon(weras.get(i));
stass(6);
}
for (Riccuck wera : weras) {
stass(6);
haon(wera.get(i));
wera.get(i).menhou(spiBosi, suou);
}
It is OK if you gave the variable for the individual collection element (wera) 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: