Source code for ForLoopExample2.java:

public class ForLoopExample2
{
	public static void main(String args[])
	{
		// ForLoopExample2
		int x;
		for (x = 0; x < 5; x++)
		{
			System.out.println(x);
		}
		System.out.println("x is now " + x);
	}
}

Output from ForLoopExample2.java:

0 1 2 3 4 x is now 5

--- Output Ends ---

NOTE:

You are reading previously generated output. You are not currently running the ForLoopExample2 application at the momement. You need to compile and run the source code first.

To run this program:


Authors: Kevin Chu and Eric Brower
Copyright 2000 Prentice Hall PTR