To complete the repetitive tasks, a computer is the most suitable machine and it works thousands of times at all times. In each programming language, instructions have been given to do such repetitive tasks with the help of certain types of statements. . The process of repeatedly implementing the statement of the statement is called looping. Many numbers are executed on the basis of the statements of the statements. But if such a situation is argued that repetition continues without any period, then to stop stopping those statements, then this type of looping is called infinite looping.
1 | while loop
Repeats a statement or group of statements
|
2 | for loop
Many times execute the sequence of statements and condenses the code which manages the loop variable.
|
3 | do...while loop
Just like the statement for a while, except that the loop examines the situation at the end of the body.
|
break statement | break; | Is used to terminate loop or switch statements. |
continue statement | continue; | It is used to suspend the execution of the current loop running and is used to move the loop to the next recurrence. |
goto statement | goto labelName;labelName: statement; | It transfers the current program execution sequence to some other part of the program. |
While (condition) { statement(s); Incrementation; }
While loop Example -
public class Sample { public static void main(String args[]) { /* local variable Initialization */ int n = 1, times = 5; /* while loops execution */ while (n <= times) { System.out.println("Java while loops:" + n); n++; } } }
Do While loop Syntax -
do { statement(s); }while( condition );
Do While loop Example -
public class Sample { public static void main(String args[]) { /* local variable Initialization */ int n = 1, times = 0; /* do-while loops execution */ do { System.out.println("Java do while loops:" + n); n++; } while (n <= times); } }
For Loop Syntax -
for ( init; condition; increment ) { statement(s); }
For loop Example -
public class Sample { public static void main(String args[]) { /* local variable Initialization */ int n = 1, times = 5; /* for loops execution */ for (n = 1; n <= times; n = n + 1) { System.out.println("Java for loops:" + n); } } }
0 comments:
Post a Comment