C# for Loop

tutorial and example
tutorial and example

For loop is used to iterate a part of the code multiple times.  We must use for loop instead of using while and do while if the number of iteration is known in advance.

For loop in C# is same as it was In C and C++.

Syntax:

C# for loop example:

Output

C# Nested for loop Example:

Output

C# Infinite for loop:

An infinite loop is the one which iterates infinite number of times. the for loop becomes an infinite loop if the condition provided is never going to be fulfilled.

C# infinite for loop Example:

If we put two semicolons only in for loop then the loop will iterate till infinite times. this is the simplest way to create an infinite for loop.