Nested Loops in C with Examples
SOURCEH
Nested loop means a loop statement inside another loop statement. That is why nested loops are also called as “loop inside loop“.
Syntax for Nested For loop:
for ( initialization; condition; increment ) { for ( initialization; condition; increment ) { // statement of inside loop } // statement of outer loop }
Syntax for Nested While loop:
while(condition) { while(condition) { // statement of inside loop } // statement of outer loop }
Syntax for Nested Do-While loop:
do{ do{ // statement of inside loop }while(condition); // statement of outer loop }while(condition);
Note: There is no rule that a loop must be nested inside its own type. In fact, there can be any type of loop nested inside any type and to any level.
Syntax:
do{ while(condition) { for ( initialization; condition; increment ) { // statement of inside for loop } // statement of inside while loop } // statement of outer do-while loop }while(condition);
SOURCE :https://www.geeksforgeeks.org/nested-loops-in-c-with-examples/
Tidak ada komentar:
Posting Komentar