C# For Loop

C# For Loop

The for loop in C# is used to repeat a block of code a specific number of times. It is best when you know in advance how many iterations are required.


 Basic for Loop Syntax



 Simple Example


Output:

1
2
3
4
5

 For Loop Flow

  1. Initialize variable

  2. Check condition

  3. Execute code

  4. Update variable

  5. Repeat until condition is false


 Loop with Different Increment



 Reverse for Loop



 Multiple Variables in for Loop



break in for Loop


 


continue in for Loop


 


 Nested for Loop



 Common Uses

✔ Printing patterns
✔ Iterating arrays
✔ Counting loops
✔ Mathematical tables


 Summary

for loop is used for fixed iterations
✔ Contains initialization, condition, update
✔ Supports break and continue
✔ Can be nested

You may also like...