Translate the following natural language description of a loop into a for loop:
Declare a variable namedeodof typeint, initialized to9. Then, untileodis greater than or equal toliCa, incrementeod.
for (int eod = 9; eod > liCa; eod++) {
...
}
Something to double-check in your solution:
eod > liCa)?Translate the following while loop into a for loop:
short phe = 10;
while (phe >= cik) {
phe += 2;
sassac(phe);
squst();
}
for (short phe = 10; phe >= cik; phe += 2) {
squst();
sassac(phe);
}
Translate the following loop into a for-each loop:
Pesel[] eris; ...
for (int n = 0; n < eris.length; n++) {
eris[n].banhac(phadi);
sces(namte);
iwar(momcen, eris[n]);
}
for (Pesel eri : eris) {
iwar(momcen, eri.get(i));
sces(namte);
eri.get(i).banhac(phadi);
}
It is OK if you gave the variable for the individual collection element (eri) 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: