
Syntax of Nested while loopĮxample 1: C program to print the number pattern.Ī number is said to be composite if it has at least one factor other than 1 and itself.

Nested while loopĪ while loop inside another while loop is called nested while loop. a for loop inside a while loop, or a while loop inside a do-while loop. Note: There can be mixed type of nested loop i.e. Then, the total number of times the inner loop runs during the program execution is n*m. Consider a nested loop where the outer loop runs n times and consists of another loop inside it. We can have any number of nested loops as required. The depth of nested loop depends on the complexity of a problem. Let's see an example on how to make a for loop infinite.A loop inside another loop is called a nested loop. When the conditional expression is empty, it is assumed to be true. We can make an infinite loop by leaving its conditional expression empty. These loops occur infinitely because their condition is always true. There may exist some loops that can iterate or occur infinitely. What if loop goes on and on - Infinite Loop

But you need to solve questions to make your base in coding concrete. We just saw three different types of loops which are used to repeat a certain process some number of times and they were fun as well, I hope. After this, the condition becomes false and the loop terminates. When the value of 'a' is 10 and 'Hello World' is printed for the tenth time, a++ increases the value of 'a' to 11. Since the value of 'a' is 1, so the condition is satisfied.Īgain the code inside the body of loop is executed and the value of 'a' becomes 2. If the condition is found true, then statements written in the body of the while loop i.e., inside the braces ) is executed, condition 'a <= 10' is checked. While loop checks whether the condition written in ' ( )' is true or not.

Now, let's understand each line of the code.įirst, have a look at the syntax of a while loop.

Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
