Skip to content

Instantly share code, notes, and snippets.

@arsalankhan994
Last active December 27, 2021 15:32
Show Gist options
  • Save arsalankhan994/1ab4a89129dd89b1c6bb443f5b63909e to your computer and use it in GitHub Desktop.
Save arsalankhan994/1ab4a89129dd89b1c6bb443f5b63909e to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.List;
public class LoopsInJava {
public static void main(String[] args) {
List<String> list = new ArrayList<>();
list.add("Erselan");
list.add("Khan");
/*
1. for loop
*/
for (int i=0; i<5; i++) {
System.out.println("Erselan Khan");
}
/*
2. foreach loop
*/
for (String value : list) {
System.out.println(value);
}
/*
3. while loop
*/
int loopValue = 5;
while (loopValue > 0) {
System.out.println("Erselan Khan");
loopValue--;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment