LOOP CONTROL STATEMENT
IF-ELSE STATEMENT
SWITCH OPERATOR
There are three types of loop
1 . FOR LOOP
2. WHILE LOOP
3. DO WHILE LOOP
FOR LOOP
A for loop is usually used to execute a piece of code for a specific number of time
WHILE LOOP
If the number becomes false, the while loop keeps getting executed, such a loop is known as while loop
Do while loop
this loop is similar to while loop except for the fact that is guaranteed to execute at least once
NOW THAT TIME WE USE ADVANCED OR ENHANCED FOR LOOP
for-each loop
The for-each loop introduced in JAVA 5, it is mainly used to traverse array or collection element, the advantage for each loop is that it eliminates the possibility of bugs and makes the code more readable.
Advantage of for each loop :
Syntax of for each loop
LABELLED LOOP
According to nested loop, if we put break statement in inner loop, compiler will jump out from inner loop and continue the outer loop again, what if we need to jump out from the outer loop using break statement given inside inner loop? the answer is we should define label along with colon (i) sign before loop.
BREAK STATEMENT
the break statement is used to exit the loop irrespective of whether the condition is true or false.
whenever a break is encountered inside the loop, the control is sent outside the loop.
0 Comments