Count and gets to the number 12 then aborts the loop - Java Language Basics

Java examples for Language Basics:break

Description

Count and gets to the number 12 then aborts the loop

Demo Code

public class Main
{
  public static void main(String[] args)
  {//ww w .  j  a va 2s  .c  o m
    int number = 2;
    while (number <= 20)
    {
      if (number == 12)
        break;
      System.out.print(number + " ");
      number += 2;
    }
    System.out.println();
  }
}

Related Tutorials