In C#, you can write a for loop using the following syntax:
main.cs92 chars5 lines
The initialization
statement is executed only once at the beginning of the loop. It is typically used to initialize the loop variable.
The condition
statement is evaluated at the beginning of each iteration of the loop. If the condition is true, the loop executes; otherwise, it ends.
The increment/decrement
statement is executed at the end of each iteration of the loop. It is typically used to increment or decrement the loop variable.
Here's an example of a for loop that prints the numbers from 1 to 10:
main.cs68 chars5 lines
Output:
main.cs21 chars11 lines
gistlibby LogSnag