Nested Loops in C || Lesson 37 || C Programming || Learning Monkey ||

Published: 05 July 2021
on channel: Learning Monkey
3,994
71

Nested Loops in C

In this class, we will try to understand Nested Loops in C.

We have already discussed while, do-while, and for loops.

Table of Contents

Nested Loops
Nested Loops Examples
Nested Loops Output

Nested Loops

Nested loops are the use of a loop in another loop.

Nested loops are very frequently used in programming practices.

Though the definition looks very simple, nested loops will have a greater impact on the output.
Nested Loops Examples

We will try to understand the use of nested loops with an example.

The image below is a programming example to understand nested loops.
Nested Loops in C Example
Nested Loops in C Example

The above program prints the given number of multiplication tables by the end-user.

If the user asks for five multiplication tables, the program will print the tables from 1 to 5.

The above program uses a two-level nesting.

We can do the nesting of the loops to any level.

Any loop can be nested in another loop; this means a ‘for loop can be nested in a while loop, or a while loop can be nested in a do-while loop.

The outer for-loop in the program will iterate for n times.

The value of n is the number of tables to be printed.

Every time we enter the outer for loop, the inner for loop will iterate ten times.

Now can you guess how many times the inner loop iterates for a value of n as 5?

The inner loop will iterate 50 times.

Try to think about this concept of iteration until you get the clarity.

The printf(“%d * %d = %d\n”, i, j, (i*j)); function of the inner for loop will print the multiplication table.
Nested Loops Output

The output of the program for the value of n = 5 is shown in the image below.

#learningmonkey #cprogrammingforbeginners #placements #gatecse #cprogramming #cprogramminglanguage

Link for playlists:
   / @learningmonkey  


Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ [email protected]


On this page of the site you can watch the video online Nested Loops in C || Lesson 37 || C Programming || Learning Monkey || with a duration of hours minute second in good quality, which was uploaded by the user Learning Monkey 05 July 2021, share the link with friends and acquaintances, this video has already been watched 3,994 times on youtube and it was liked by 71 viewers. Enjoy your viewing!