This repository contains an implementation and explanation of the for loop in the C programming language. The for
loop is one of the most commonly used loops in C, allowing controlled iteration with initialization, condition checking, and increment/decrement in a single line.
- Demonstrates the syntax and working of the
for
loop. - Provides example programs for better understanding.
- Helps beginners grasp the concept through practical implementation.
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 5; i++) {
printf("%d\n", i);
}
return 0;
}
- Initialization: The loop starts by initializing
i = 1
. - Condition Checking: It checks if
i <= 5
. If true, the loop body executes; otherwise, the loop terminates. - Iteration Update: The loop variable
i
is incremented after each iteration.
1
2
3
4
5
- Clone the repository:
git clone https://github.com/Fatima-progmmer/For-loop
- Navigate to the project folder:
cd For-loop
- Compile the program using GCC:
gcc for_loop_example.c -o for_loop_example
- Run the executable:
./for_loop_example
Feel free to contribute by adding more examples, improving documentation, or optimizing the code. Fork the repository and create a pull request with your changes.
This project is open-source and available under the MIT License.
For more projects and contributions, visit my GitHub Profile.