Skip to content

fefong/java_loopFor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Loop For

Example Application: LOOP - FOR

Loop Structure

for (statement 1; statement 2; statement 3) {
  // code block to be executed in loop
}

Example 1: internal variable and simple for loop

for (int i = 0; i < 11; i++) {
	System.out.println("i: " + i);
}

Example 2: for loop with array values

int[] values = new int[] { 3, 4, 5 };
for (int i = 0; i < values.length; i++) {
	System.out.println("i: " + values[i]);
}

Example 3: decrease loop

int i;
for (i = 10; i >= 0; i--) {
	System.out.println("i: " + i);
}

Example 4: increase step N

int i;
for (i = 0; i <= 10; i += 2) {
	System.out.println("i: " + i);
}

Example 5: decrease step N

int i;
for (i = 10; i >= 0; i -= 2) {
	System.out.println("i: " + i);
}

Some links for more in depth learning