public class ForLoops
{
	public static void main(String[] args)
	{
		//Basic for loop from 0 to 9
		for (int i=0; i < 10; i++)
		{
			System.out.println("i (inside loop) = "+i);
		}

		//If we try to reference i out here, we will get a compiler error.
		//Try uncommenting the next line and recompiling if you want to see the error for yourself:
		//System.out.println(" i (outside loop) = "+i);


		//---------------------------------------------------->
		System.out.println(); //Just printing a blank line to separate the output...


		//For loop with loop variable j declared outside of the for loop statetment itself:

		int j = 99999; //I'm just setting j to an arbitrary value to show that once
			       //we enter the loop, the variable initialization part takes over.
			       //And sets the first value of j within the loop.

		System.out.println("j before for loop = "+j);

		for (j=0; j < 10 ; j++)
		{
			System.out.println("j (inside loop) = "+j);
		}

		//Just to show that j actually reaches 10, but the loop
		//does NOT execute on j=10 becuase it FAILS the test "j < 10"
		System.out.println("j immediately after the for loop = "+j);

		//We can continue to work with j if we want...
		//We can keep the value set to 10 if it's important to us
		//or reuse the variable for something else completely.


		//---------------------------------------------------->
		System.out.println(); //Just printing a blank line to separate the output...


		//For loop with a break statement to "preempt" the loop execution.

		for (int i=0; i < 10 ; i++)
		{
			System.out.println("i (inside loop) = "+i);

			if (i==5)
			{
				System.out.println("Stopping the loop at i = "+i);
				break; //This will cause the loop to stop and
				       //JUMP to the first line immediately after the loop...
			}
		}

		System.out.println("We are now out of the for loop...");
	}
}
