Java Language / Java Looping StatementsIt is a part of the program (sequence of instructions / part of code) which is repeated to perform a particular tasktill a certain condition is meets. It is used save time, reduce errors and make code more readable.There are 3 looping Statements in java.They were 1. While Loop. 2. Do While Loop. 3. For Loop. While Loop It is used to repeat a Block / Lines of code to be executed till it meets a certain condition.But this loop first checks the condition of the loop and then it enters into the code block.It the condition is false it comes out of the loop. Syntax while (condition) { // Block / Lines of code to be executed }
Do While Loop It is used to repeat a Block / Lines of code to be executed till it meets a certain condition. But in this loop first it enter into the code block and then checks the condition of the loop till the condition is false it comes out of the loop. Syntax do { // Block / Lines of code to be executed } while (condition);
For Loop It is used to repeat a Block / Lines of code to be executed till it meets a certain condition. But in this loop first it enter into the code block and then icrement / decrements the counters and thenchecks the condition of the loop till the condition is false it comes out of the loop. Syntax for (Initialization; Condition; Increment / Decrement) { // Block / Lines of code to be executed }
|