Java Tutorial 21- Loops in Java - Study Viral
Loops are also known
as an iteration statements.
Loops are used to
repeat some set of code again and again until some condition is true.
In Java there are
FOUR type of loops.
- while loop
- do-while loop
- for loop
- Enhanced for loop
Loop Requirements
- Loop control variable
- Initialize the loop control variable
- Condition Check for loop
- Increment/Decrements
Syntax While Loop int a; // Loop Control Variable a = 0; // Initialize Variable while (a < 4) // Condition Check { System.out.println(“a :: ”+a); a++; // Increment } | Syntax do-while Loop int a; // Loop Control Variable a = 0; // Initialize Variable do{ System.out.println(“a :: ”+a); a++; //Increment } while (a < 4); // Condition Check |
||||||||||||||||||||||||
Syntax for Loop for( int i =0 ; i < 4 ; i++) { System.out.println(“a :: ”+a); } |
|
0 comments:
Post a Comment