Loops examples and Pyramid Pattern

For loop

Summary:

Loops examples and Pyramid Pattern

Example: following is the example to print a list of elements for normal for loop.

Loops examples and Pyramid Pattern

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.

Loops examples and Pyramid Pattern

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:

Loops examples and Pyramid Pattern

-A blog by Shwetali Khambe

Related Posts