The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop.
There are three types of for loops in Java.
## types of loops
initialize the variable, check condition and increment/decrement value. It consists of four parts:
Syntax:
for(initialization; condition; increment/decrement){
//statement or code to be executed
}
]
The Java while loop is a control flow statement that executes a part of the programs repeatedly on the basis of given boolean condition.
If the number of iteration is not fixed, it is recommended to use while loop.
Syntax:
while(condition){
//code to be executed
}
The Java do while loop is a control flow statement that executes a part of the programs at least once and the further execution depends upon the given boolean condition.
If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use the do-while loop.
Syntax:
do{
//code to be executed
}while(condition);
Package = directory. Java classes can be grouped together in packages.
The first statement, other than comments, in a Java source file, must be the package declaration.
import javax.swing.*;
The wildcard character (*) is used to specify that all classes with that package are available to your program.
import javax.swing.JOptionPane;
javax.swing.JOptionPane.showMessageDialog(null, "Hi");