Loops

Execute code blocks repeatedly using for, foreach, while, and do...while loops.

Loops are constructions that allow us to execute a block of code multiple times until a certain condition is met. We have several types of loops in C#:

  • The for loop

  • The foreach loop

  • The while loop

  • The do...while loop

The for loop

The syntax of the for loop consists of an initialization, a condition, and an iterator.