Intro
This examples, will demonstrates how to use a break statement in for loop statement. Break statement used to exit from looping state.
Examples
package com.freesamplecode.java.basic;
public class ForLoopBreakDemo {
public static void main(String[] args){
int[] anInt = {1, 2, 3, 4, 5};
for(int i = 0; i < anInt.length; i++ ){
if(i == 3){
break;
}else{
System.out.println(anInt[i]);
}
}
}
}
Output
1 2 3

0 comments: