import java.util.Scanner;
public class LoopPractice {
public static void main(String[] args) {
// For Loop Example
System.out.println("Here is an example of a for loop. \"i\" is the counter");
System.out.println("Why does 1 not get printed out?");
for(int i=10; i>1; i--){
System.out.println("The value of i is: "+i);
}
// While Loop Example
System.out.println("Here is an example of a while loop. \"i\" is set to 10");
int i=10;
while(i>=1){
System.out.println("The value of i is: "+i);
i--;
}
// While Loop Example that requires user input
System.out.println("Here is an example of a while loop that continues a process until the user exits.");
Scanner userInput = new Scanner(System.in);
int input=0;
System.out.println("Please enter a number. To quit enter 10.");
while(input!=10){
System.out.println("The value of input is: "+input);
input = userInput.nextInt();
}
System.out.println("You have entered a value of 10 and have chosen to quit the program.");
System.out.println("Thank you for using my program, please come back again.");
System.out.println("\nThis is a Do While statement.");
int loopCounter=10;
do{
System.out.println("This line will ALWAYS print in a Do While statement.");
System.out.println("The value of the loopCounter is: " + loopCounter);
loopCounter--;
}while(loopCounter>1);
}
}