vault backup: 2023-10-05 09:18:23
This commit is contained in:
25
Prog/Loops.md
Normal file
25
Prog/Loops.md
Normal file
@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
```
|
Reference in New Issue
Block a user