Java – for loop

for loops executes some statements repeatedly, while one condition evaluates to true.

syntax:

for (initialization; test; update expression){
statements
}

example:

for loop, <span>Java – for loop</span>, KandZ
for loop, <span>Java – for loop</span>, KandZ

count down loop:

for loop, <span>Java – for loop</span>, KandZ
for loop, <span>Java – for loop</span>, KandZ

Nested loops:

public static void main(String[] args) {

for (int a=0; a<=10; a++){
for (int b=0; b<=10; b++) {
System.out.print(a + ":" + b + " ");
}
System.out.println("\n");
}
}
for loop, <span>Java – for loop</span>, KandZ

Notice that in nested loops, first the inside loop will be executed and then the outer loop will execute 1 step. Then again the inside loop …

THE END!!!

86680cookie-checkJava – for loopJava – for loop

Related posts

2 Thoughts to “Java – for loop

Comments are closed.