Studyon Minte9.com
Head First (Java)




Loops



		// for(int i=0
		// increment operator
		// while(i<10
		// for(String name:names

* For

	%java

		for (int i=0; i<10; i++) {
			System.out.println(i);
		}


* Increment operator

	The placement of the operator (either before or after the variable) can affect the result.
	x++ is different from ++x

	%java

		int x = 0;
		int z = x++;
		System.out.println(x); // 1
		System.out.println(z); // 0


* While
	
	A while loop has only the boolean test; It doesn't have a built-in it initialization or Iteration expression.
	A while loop is good when you don't know how many times to loop and just want to keep going while 
	some condition is true.

	%java

		int i = 0;
		while(i<10) {
		    System.out.println(i);
		    i++;
		}

* For (each)

	Beginning with Java 5.0 (Tiger), the Java language has a second kind ofJor loop called the enhanced, 
	that makes it easier to iterate over all the elements in an array or other kinds of collections.

	%java

		String[] names = {"aaa", "bbb", "ccc"};
		for(String name:names) {
		    System.out.println(name);
		}