Loops are used to customize and execute repetitive piece of code using single instruction set. This helps in optimization and reducing redundancy of code. Loops are used in order to to execute same block of code again and again as per required conditions. Loops same a lot of Coding and execution time.
Types of loops and keywords in Java
The for loop : This executes the statement based on no. of iterations. Break keyword : Helps in exiting the loop. Continue keyword : Used to skip a condition in Loop. The while loop :This executes the statement based on unknown no. of iterations. The do-while loop : This executes the statement at least once. Enhanced for loop : Modified for loop. This loop works with arrays, Hash-maps of any Datatype.
A loop within a loop is called a nested loop.
Sample program demonstrating Loops and Keywords in Java:
Next Chapter >>>> It's in the oven, will be ready soon!