epicours/Prog/Loops.md

26 lines
390 B
Markdown

In C#, loops are called iteration statements. We need to master both, recursion and loops. There are 3 kinds of loops in C# :
- while and do (...) while
- for
- foreach
## While loop
```cs
while (<condition>)
{
// repeat stuff
}
```
The ``condition`` is a boolean
**Example**
```cs
unit SumWhile(unit n)
{
uint loop = 0;
while (n > 1)
{
loop += 1;
n = n - 1;
}
return loop;
}
```