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

Veröffentlicht am: 05 Juli 2021
auf dem Kanal: 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]


Auf dieser Seite können Sie das Online-Video Nested Loops in C || Lesson 37 || C Programming || Learning Monkey || mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Learning Monkey 05 Juli 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,994 Mal angesehen und es wurde von 71 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!