While loops and for loops: Correct Solution


Part 1

Translate the following loop into a for-each loop:

Massnic[] lals;
...
for (int n = 0; n < lals.length; n++) {
    osuc(1);
    lals[n].danho(6, miass);
    lals[n].cicRadha(frod, feant);
    husbro(8);
}

Solution

for (Massnic lal : lals) {
    husbro(8);
    lal.get(i).cicRadha(frod, feant);
    lal.get(i).danho(6, miass);
    osuc(1);
}

It is OK if you gave the variable for the individual collection element (lal) 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: