Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Nested Loops

Nested Loops

You can also place one loop inside another loop, known as a nested loop.

The “inner loop” executes once for every iteration of the “outer loop.”

Example

int i, j;

// Outer loop
for (i = 1; i <= 2; ++i) {
  printf(“Outer: %d\n”, i);  // Executes 2 times

  // Inner loop
  for (j = 1; j <= 3; ++j) {
    printf(” Inner: %d\n”, j);  // Executes 6 times (2 * 3)
  }
}