// 10/25/2017

/** Introducing the for loop
 */

import java.util.Scanner;

public class ForLoop {
  /** ForLoop introduces the for loop and its components.
   */
  
  public static void main(String[] args)   {
    // want to number 5 lines with colon
    for (int i=1; i<=5; i++)  // i is declared in the initialization of loop
      // hence its scope is only in this for loop 
      System.out.println(i + ":");
    // want to print the numbers in descending order, 5, 4, ...
    for (int i=5; i>=1; i--) { // can reuse same var name i since its a different scope
      System.out.println(i + ":");
    }
    // at this point, i is not ACCESSIBLE since it is out of scope
    
    int j; // declare my "counter" variable for the for loop
    // if you want access to j outside the for loop, declare it before
    // entering loop.
    for (j=1; j<=10; j++) {
      System.out.print(j + " ");
    }
    System.out.println();// go to next line in output screen
    
    // fall out of loop, is j accessible? YES.
    System.out.println("fall out of loop, j's value is: " + j);
   }
}