Getting Started With C

for statement

A for loop is a control flow statement used in programming to iterate a specific number of times or over a sequence (such as a range of values) to execute a block of code repeatedly.

Syntax:

  for (initialization; condition; increment/decrement) { 
      // code block to be executed 
      }
      
 

Explanation:

  
  • Initialization: It initializes the loop control variable to a starting value.
  • condition:The loop continues iterating as lonf as this condition remains true.
  • Increment/Decrement: It updates the loop control variable after each iteration.
  • Loop Body: The block of code executed repeatedly until the condition becomes false.
  • Control Variable: It's typically used to track the loop's progress.
  • Defined Iteration: The loop executes a specific number of times or operates over a predefined sequence.
  • Sample code:

    Program.c

    output:

    output.c

    Resources :

    Featured
    Special title treatment

    With supporting text below as a natural lead-in to additional content.

    Q1. For loop in a C program, if the condition is missing?

    Q2. Which of the following statement about for loop is true?