When the break statement is encountered inside a loop, the loop is immediately stopped and program control resumes at the next statement following the loop.
{
public static void main(String args[])
{
int i = 0; = Integer.parseInt(args[0]);
while(i < args.length)
{
if(args[i] == 0)
{
break;
}
System.out.println(Array index " + (i+1) + " has value " + args[i++]);
}
}
}
// Call from command line
java BreakStatLoop 10 20 30 40 50 0
Output
Array index 1 has value 10
Array index 2 has value 20
Array index 3 has value 30
Array index 4 has value 40
Array index 5 has value 50