for loop in C | syntax | Flowchart

 

for loop in C

The for loop in C language is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like the array and linked list.


for loop in C


The for loop has the following syntax:

c
for (initialization; condition; iteration) { // Code to be executed in each iteration }


Here's a breakdown of the components of a for loop:

1. Initialization: This part is typically used to initialize a loop control variable. It is executed only once at the beginning of the loop.


2. Condition: This is a Boolean expression that determines whether the loop should continue to execute. As long as the condition is true, the loop will keep running. If the condition becomes false, the loop terminates.


3. Increment/Decrement: This part is used to update the loop control variable after each iteration of the loop. It can be used to increase or decrease the loop control variable.

Flowchart of for loop in C


for loop in C

c for loop Examples:

c
#include <stdio.h> int main() { for (int i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; }
Output.:
1 2 3 4 5

Post a Comment

0 Comments