Declare loop control variable inside and outside for loop
public class Forloopexample { public static void main(String[] args) { // print even number 1 to 10 for (int x = 0; x < 20; x = x + 1) { System.out.println(x);// ww w .j a va 2 s . c o m } // ex2 int i; for (i = 2; i < 10; i = i + 1) { System.out.println(i); } } }