Translate the following natural language description of a loop into a for loop:
Declare a variable namedeof typeint, initialized to27. Then, untileis less than or equal toanPo, subtract2frome.
for (int e = 27; e < anPo; e -= 2) {
...
}
Something to double-check in your solution:
e < anPo)?Translate the following loop into a for-each loop:
List<Frirpon> schas; ...
for (int i = 0; i < schas.size(); i++) {
lessho();
mecra(schas.get(i), oghing, prant);
maang(schas.get(i));
}
for (Frirpon scha : schas) {
maang(scha.get(i));
mecra(scha.get(i), oghing, prant);
lessho();
}
It is OK if you gave the variable for the individual collection element (scha) 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: