C for Loop

You are Here:

C for Loop

The for loop executes a block of code for the specified number of times.

Syntax

for(initialStatement; testCondition; updateStatement){ // code block }

Simple for Loop

In the following program, we will print 'Hello World' for 5 times using for loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; for(i=0; i<5; i++){ printf("Hello World \n"); } return 0; }

Output

Hello World Hello World Hello World Hello World Hello World

for Loop to print numbers

In the following program, we will print numbers from 0 to 4 using for loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; for(i=0; i<5; i++){ printf("%d ", i); } return 0; }

Output

0 1 2 3 4

for Loop to print Elements in a Array

In the following program, we will print all the elements in an array using for loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; char absent[3] = {13, 25, 36}; printf("Absent Roll No's are: "); for(i=0; i<3; i++){ printf("%d ", absent[i]); } return 0; }

Output

Absent Roll No's are: 13 25 36

for Loop to print Array of Strings

In the following program, we will print the array of strings using for loop.

Source Code

C Compiler
#include <stdio.h> int main() { int i = 0; char students[3][6] ={"gouri", "ram","alex"}; for(i=0; i<3; i++){ printf("%s \n", students[i]); } return 0; }

Output

gouri ram alex
congratulation

Congratulation! you have learned everything about for loop in C Programming.

Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author