// Starting on 0:for(int i =0; i <5; i++){System.out.println(i +1);}// Starting on 1:for(int i =1; i <=5; i++){System.out.println(i);}// Both for loops will iterate 5 times,// printing the numbers 1 - 5.
for(int i =0; i <10; i++){//do something//NOTE: the integer name does not need to be i, and the loop//doesn't need to start at 0. In addition, the 10 can be replaced//with any value. In this case, the loop will run 10 times.//Finally, the incrementation of i can be any value, in this case,//i increments by one. To increment by 2, for example, you would//use "i += 2", or "i = i+2"}
// Java program to illustrate // for-each loopclassFor_Each{publicstaticvoidmain(String[] arg){{int[] marks ={125,132,95,116,110};int highest_marks =maximum(marks);System.out.println("The highest score is "+ highest_marks);}}publicstaticintmaximum(int[] numbers){int maxSoFar = numbers[0];// for each loopfor(int num : numbers){if(num > maxSoFar){
maxSoFar = num;}}return maxSoFar;}}
//For Loop in JavapublicclassForLoops{publicstaticvoidmain(String[] args){for(int x =1; x <=100; x++){//Each execution of the loop prints the current value of xSystem.out.println(x);}}}
classMain{publicstaticvoidmain(String[] args){char[] vowels ={'a','e','i','o','u'};// iterating through an array using a for loopfor(int i =0; i < vowels.length;++ i){System.out.println(vowels[i]);}}}
// Java program to illustrate for loopclass forLoopDemo {publicstaticvoidmain(String args[]){// Writing a for loop// to print Hello World 5 timesfor(int i =1; i <=5; i++)System.out.println("Hello World");}}
packagecom.company;publicclassMain{publicstaticvoid main (String[] args){System.out.println("loop started");for(int i =0; i <10; i++){if(i==5){continue;}System.out.println(i);}System.out.println("loop over");}}