Java examples for Language Basics:for
Breaking and continuing your for loops
public class Main { public static void main(String[] args) {//from w w w . j a v a 2 s. c om for (int number = 2; number <=20; number += 2) { if (number == 12) break; System.out.print(number + " "); } System.out.println(); } }