Flow Control Quick Reference

A detailed discussion of flow control can be found in the Java Tutorial

Decisions: The If

if ( condition ) {
	true case;
} 
[ else { 
	false case;
} ]

Note that the else login is optional

Examples

if ( count = 3 ) {
  out.println("Times up!");
}
...
if ( request.getParameter("gst").equals("true") ) {
  total = total + cost * amount * 1.07;
} else {
  total = total + cost * amount;
}

Loops: The While

while ( condition ) {
	true case;
} 

Note that unless code in the true case can change the condition, your program will not exit. This is caslled an infinite loop

Examples

int size = 38;
while( size  < 10000 ) {
  size = size * 2;
}
...
Enumerator enum = request.getParameterNames()
while (e.hasMoreElements()) {
    String key = (String)e.nextElement();
    String value = getInitParameter(key);
    out.println("   " + key + " = " + value); 
}

Enumerator is a special class used to step through all the elements of a list.