What isfor (String sport: olympicSports) { System.out.println(sport); }


what is the meaning of
for (String sport: olympicSports) {

Replace this line with your code.


This is a foreach loop. You have a String array olympicSports and the String variable sport that will take on each value in the array.
Here is a normal for loop that does the same thing:

String sport = "";
for (int i = 0; i < olympicSports.length; i++)
   sport = olympicSports[i];

comparing those two codes will hopefully help you understand it better.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.