Nesting of for loop



Nesting of for loop  

If a body of for loop is declared inside another for loop then it is called nesting of for loop. In simple words we can say that using a loop inside another loop is called nesting of for loop, here any loop can be used inside any loop. For example, while loop can be used inside for loop and so on for these, let's see the syntax here, 

 

Syntax (for and for loop ) 

 

for(initialization; condition; updates) 

{ 

    for(initialization; condition; updates) 

    { 

        statement(s); 

    } 

} 

 

Syntax ( for and while loop)  

for(initialization; condition; updates) 

{ 

    while(condition) 

    { 

        statement(s); 

        update(s); 

    } 

} 

 

Syntax (for and do-while loop) 

for(initialization; condition; updates) 

{ 

    do 

    { 

        statement(s); 

        update(s); 

    }while(condition); 

} 

 

Note: above loop can be changed according to the programmer's wants and need. 


Flowchart  

 

 

Program 


QUESTION:- write a program to print the following pattern(right angle triangle) according to a user input value.  

* 

* * 

* * *  

* * * * 

* * * * * 

#include <stdio.h> 

#include <conio.h> 

int main() 


    int i, j, no; 

    printf("enter a number: "); 

    scanf("%d", &no); 

    for(i = 1; i<=no; i++) 

    { 

        for(j = 1; j<=i; j++) 

        { 

            printf("* "); 

        } 

        printf("\n"); 

    } 

    return 0



OUTPUT
enter a number: 5

* 

* * 

* * *  

* * * * 

* * * * * 


Follow our page for regular updates.

0 Comments