Professional Documents
Culture Documents
}
• If the condition is true, the statement is executed
condition
evaluated
false
true
statement
int count = 1;
while (count <= 5)
{
System.out.println (count);
count++;
}
Prevent divide by 0
true
condition
evaluated
false
int x = 10;
do{
System.out.print("value of x : " + x );
x++;
System.out.print("\n");
}while( x < 20 );
}
statement
condition
evaluated
true
condition
true false
evaluated
statement
false
initialization
condition
evaluated
true false
statement
increment
initialization;
while ( condition )
{
statement;
increment;
}
//********************************************************************
// Stars.java //
// Demonstrates the use of nested for loops.
//********************************************************************
System.out.println();
}
}
}
Copyright@ 2016 Allan Ninyesiga, Uganda Technology and Management University
//********************************************************************
// Stars.java Author: Lewis/Loftus
//
// Demonstrates the use of nested for loops.
//********************************************************************
System.out.println("It is" +
((val <= 10) ? " not" : "") +
" greater than 10.");
• See EvenOdd.java
import javax.swing.JOptionPane;
continue
do
{
numStr = JOptionPane.showInputDialog ("Enter an integer: ");
num = Integer.parseInt(numStr);
do
{
numStr = JOptionPane.showInputDialog ("Enter an integer: ");
num = Integer.parseInt(numStr);