Last active
December 27, 2021 15:32
-
-
Save arsalankhan994/1ab4a89129dd89b1c6bb443f5b63909e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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