import java.util.Scanner;

class Oct11 {

	public static void main(String[] args) {

		// typical while-loop may never execute block

		int i = 5;
		while (i < 5) {
			System.out.printf("%d ", i++);
		}
		System.out.println();

        // do-while loops execute block at least once

		do {
			System.out.printf("%d ", i++);

		} while(i < 5);
		System.out.println();

        // do-while used with menu - menu prints at least once

		Scanner kb = new Scanner(System.in);
		char option = '\0';
		do {
			System.out.println("Enter option [r]un, [e]xit: ");
			option = kb.next().charAt(0);
			System.out.printf("option entered: %c\n", option);

		}while(option != 'e');

	    // menu implemented with if-else-if chain.

		option = '\0';
		do {
			System.out.println("Enter option [r]un, [s]top, [e]xit: ");
			option = kb.next().charAt(0);

			if(option == 'r') {
				System.out.println("running");
			}
			else if (option == 's') {
				System.out.println("stopping");
			}
			else {
			    System.out.println("all other cases");
			}

		}while(option != 'e');

		// switch statements - equivalent to if-else-if chain.

		option = '\0';
		do {
			System.out.println("Enter option [r]un, [s]top, [e]xit: ");
			option = kb.next().charAt(0);

			switch(option) {
				case 'r':
					System.out.println("running");
					break;	
				case 's':
					System.out.println("stopping");
					break;	
				default:
					System.out.println("all other cases");

			}

		}while(option != 'e');

        // switch statements can switch on int, char, and strings
        // example switching on String

		String choice = null;
		do {
			System.out.println("Enter option [run], [stop], [exit]: ");
			choice = kb.next();

			switch(choice) {
				case "run":
					System.out.println("running");
					break;	
				case "stop":
					System.out.println("stopping");
					break;	
				default:
					System.out.println("all other cases");

			}

		}while(!choice.equals("exit"));

		// break keyboard breaks out of a loop's block

		i = 0;
		System.out.println("Enter num between 0 and 10");
		int input = kb.nextInt();

		while(i < 10) {
			System.out.printf("%d ", i);
			if (i == input) {
				break;
			}
			i++;
			System.out.printf("looping\n");	
		}

        // continue keyword relocates execution to boolean express for the loop

		i = 0;
		System.out.println("Enter num between 0 and 10");
		input = kb.nextInt();

		while(i < 10) {
			System.out.printf("%d ", i);
			i++;
			if (i == input) {
				continue;
			}
			System.out.printf("looping\n");	
		}
	}

}
