For loop
Summary:
Example: following is the example to print a list of elements for normal for loop.
We can also use the for-each loop to print elements inside the array/list. Only if we are not required to print the position of an array.
We can see that for each loop code size is much reduced than normal for loop. It’s recommended to use java-8 for each loop whenever possible to reduce the code size.
Following is the example for printing pattern using for nested for loop: