vault backup: 2023-10-05 09:27:25
This commit is contained in:
parent
37c662ef10
commit
ba47331c40
@ -23,3 +23,44 @@ unit SumWhile(unit n)
|
||||
return loop;
|
||||
}
|
||||
```
|
||||
### Iteration statements - do (..) while
|
||||
```cs
|
||||
do
|
||||
{
|
||||
// Repeat stuff
|
||||
} while (condition)
|
||||
```
|
||||
Same thing that the other one but return in a different way
|
||||
**Example**
|
||||
```cs
|
||||
uint SumDoWhile(uint n)
|
||||
{
|
||||
uint loop = 0;
|
||||
do
|
||||
{
|
||||
loop += 1;
|
||||
n = n - 1;
|
||||
} while (n > 1):
|
||||
return loop;
|
||||
}
|
||||
```
|
||||
|
||||
## For loop
|
||||
```cs
|
||||
for ([initialize]; [condition]; [iterator])
|
||||
{
|
||||
// Repeat stuff
|
||||
}
|
||||
```
|
||||
**Example:**
|
||||
```cs
|
||||
uint SumFor(uint n)
|
||||
{
|
||||
uint res = 0;
|
||||
for (uint i = 1; i < n; ++i)
|
||||
{
|
||||
res += 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user