Java - For Statement

> Procedural Languages > Java

1 - About

The for statement is a part of the control flow possibility of Java.

The Iterable interface must be implemented in order to use it. See for example: Java - Iterator Implementation

Advertising

3 - Syntax

3.1 - General

for (initialization; termination; increment) {
    statement(s)
}

3.2 - Enhanced

for (datatype variable : collections or array) {
    statement(s)
}

4 - Infinite

for ( ; ; ) {
 
    // your code goes here
}

5 - Skip

The continue statement skips the current iteration of a for loop.

6 - Example

6.1 - Counter

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

6.2 - Array

Java - Array

int[] anArray= {1,2,3,4,5,6,7,8,9,10};
for (int i = 0; i < anArray.length; i++) {
	System.out.println(i+" : "+anArray[i]);
}
Advertising

7 - Documentation / Reference

lang/java/for.txt · Last modified: 2017/02/12 21:05 by gerardnico