Incremental Java
What is Control Flow?

Straight Line Code

Consider this code in some main().
public class Foo 
{
   public static void main( String [] args )
   {
      System.out.println( "One" ) ;
      System.out.println( "Two" ) ;
      System.out.println( "Three" ) ;
      System.out.println( "Four" ) ;
   }
}
If you run main(), what gets printed?
One
Two
Three
Four
That's because we're looking at straight-line code. The first statement runs, then the second, then the third, and so on. We run one statement after the next until we reach the end of main(), and then the program is done.

What if you wanted to skip a statement some of the times? Or run one statement when some condition is true, but another when that condition is false? Or if you wanted to repeat statements over and over until some condition is met?

Control flow constructs control which statements are run, and when. They allow you to do more than straight-line code. These control flow constructs are really the essence of programming in Java. Control flow constructs and method calls make up the two primary ways that you have to control what code gets run.