Foreach Loop

This is a compact version of the for loop. Mainly used for looping through arrays and collections.


for(element : collection) {
    // Code here runs for each element.


String[] languages = {"Java", "C++", "C#", "JavaScript", "Elixir"};
for(String language : languages){
    // will execute this for each of the language in the languages array

results matching ""

    No results matching ""