Home C Programming Language / Programs / For loop Example Program in C Programming Language
🚀 Programming Example

For loop Example Program in C Programming Language

👁 1,398 Views
💻 Practical Program
📘 Step Learning
A loop is used for executing a block of statements repeatedly until a given condition returns false.

💻 Program Code

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

🖥 Program Output

1
2
3
4
5
Press any key to continue . . .
                            

📘 Explanation

Step 1:?First initialization happens and the counter variable gets initialized.
Step 2:?In the second step the condition is checked, where the counter variable is tested for the given condition, if the condition returns true then the C statements inside the body of for loop gets executed, if the condition returns false then the for loop gets terminated and the control comes out of the loop.
Step 3:?After successful execution of statements inside the body of loop, the counter variable is incremented or decremented, depending on the operation (++ or ?).

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.