For Loop Example
public class ForLoop {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
System.out.println("Value : " + i); /*will display the value of i
until the condition i<5 is true */
}
String[] myString = new String[]{"one", "two", "three", "four"};
System.out.println("
Enhanced for loop");
System.out.println("--------------------");
for (String str : myString) { /*iterating each string in the string array mystring*/
System.out.println(str);
}
}
}
Output:
Value : 0
Value : 1
Value : 2
Value : 3
Value : 4
Enhanced for loop
--------------------
one
two
three
four