☞ Following is the syntax of for loop.
for(initialization; condition; flow){ statement1; statement2; …………. }
☞'for' is a keyword.
☞Exactly two semicolons are mandatory inside for's parenthesis.
☞Whatever written before the first semicolon is executed first, then control moves to condition part, which is written between the semicolons. Condition is evaluated as true or false. If it is false, control simply skipped for’s block. If the condition is true control enters into the for’s block. After executing statements residing in the for’s block, control jumps up to the flow section, which is written after the second semicolon in the parenthesis. Control again moves to the condition part and process repeats.
//Printing 'inspirewebsoft' five times.
public class ForExample {
public static void main(String[] args) {
for(int i=1;i<=5;i++) {
System.out.println("inspirewebsoft");
}
}
}
inspirewebsoft inspirewebsoft inspirewebsoft inspirewebsoft inspirewebsoft