
public class LoopIntro {

	public static void main(String[] args) {
		//loops: repeat some section of code
		//while loops
		// 1. Where do we start? (initialization)
		// 2. When do we stop? (condition)
		// 3. How do we move?
		// 4. What do we repeat?
		
		//print the same thing 10 times.
		//1. starting point
		int count = 1;
		
		//2. Condition - true to keep going
		while(count <= 5) {
			//4. repeat
			System.out.println("the same thing");
			
			//3. How to move
			count = count + 1;
		} //end while
		
		//another loop
		count = 1;   //1
		
		while(count <= 8 ) {  //2
			//%3d indicates a field width of 3
			System.out.printf("%3d", count); //4
			++count; //3
		}
		System.out.println(); //end the line
		
		//print out the numbers from 10 to 20 one per line
		count = 10;
		while(count <= 20) {
			System.out.println(count);
			count += 1;
		}
		
		//count from 1 to 19 by 2
		count = 1;
		while(count <= 20) {
			System.out.println(count);
			count += 2;
		}
		
		//count from 10 down to 1
		count = 10;
		while(count >= 1) {
			System.out.println(count);
			count = count - 1;
		}
		
		//calculate the sum of numbers 1..1000
		int sum = 0;
		count = 1;
		while(count <= 1000) {
			sum = sum + count;
			
			count++;
		}
		System.out.printf("The sum is %d\n", sum);
		
		//print out 0, 0.1, 0.2, 0.3, up to 1.0
		double x = 0;
		while(x <= 1.0) {
			System.out.printf("%f\t", x);
			System.out.println(x);
			x += 0.1;
		}
		
		
		
		System.out.println("Done");
		
	}

}
