Nested loops

This is one of the most important concepts. All the programming logic comes from the nested loops. If you can grasp the concept behind it, it will be easy for you to solve the programming examples in Java. So, first of all, I will write one syntax:

for(int i=1;i<=4;i++)  // this block will loop for 4 times{}

The preceding syntax means that the loop will run four times. What if we write one more for loop inside the preceding block? The concept of implementing a loop within a loop is called nested loops:

     for(int i=1;i<=4;i++)       // (outer for loop) it will loop for 4 times     {         System.out.println("outer loop started");         for(int j=1;j<=4;j++) //(inner for loop)         {             System.out.println("inner loop");         } System.out.println("outer loop finished"); ...

Get Hands-On Automation Testing with Java for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.