nested-loop Archives - SoftUni Global https://softuni.org/tag/nested-loop/ Learn Programming and Start a Developer Job Sun, 08 Jan 2023 22:09:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.3 https://softuni.org/wp-content/uploads/2022/04/cropped-SoftUni-Global-Logo-Square-notext-32x32.png nested-loop Archives - SoftUni Global https://softuni.org/tag/nested-loop/ 32 32 What are Nested Loops? – Java Basics Tutorial (Part 9) https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/ https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/#respond Mon, 25 Oct 2021 11:07:00 +0000 https://softuni.org/?p=10142 In this lesson, we’ll try to untangle the complexity of Nested Loops.

The post What are Nested Loops? – Java Basics Tutorial (Part 9) appeared first on SoftUni Global.

]]>

A nested loop is the placement of a loop inside another loop to execute the operations that need multiple loop traversals, such as printing star patterns. Although it helps to make our task easier, it also increases the complexity of the program thus must be used efficiently.

Now, onto the important part: if a loop exists inside the body of another loop, it is called a nested loop. It has no limitations that only similar types of loops can be nested.

We can nest any loop inside any other loop, such as while loop inside for loop, and all different combinations are accepted.

 

In the chart, first, when we enter the body of the program, a statement such as initialization gets executed. Once a loop is found, the program checks for the condition for the outer loop, and if it returns true, it enters the loop. Once it enters the outer loop and encounters the inner loop, variables are initialized if any are present. Then it checks the condition for the inner loop, and if it returns true, the program enters into the inner loop. This procedure is repeated several times, and then the program exits from the second loop, then the first loop, and move to statements present after the loop.

Lesson Topics

In this tutorial we cover the following topics:
  • Complex Loops
  • Nested Loops
  • Nested For-Loops
  • Nested While Loops
  • Nesting While and For Loops

Practical Exercises

Watch the video and solve the problemsTo better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.

Submit your code in the SoftUni Judge System:

Exercises: Problem Description

Lesson Slides

The post What are Nested Loops? – Java Basics Tutorial (Part 9) appeared first on SoftUni Global.

]]>
https://softuni.org/code-lessons/what-are-nested-loops-java-basics-part-9/feed/ 0