diff --git a/Prog/Loops.md b/Prog/Loops.md index 89ea842..f8965e4 100644 --- a/Prog/Loops.md +++ b/Prog/Loops.md @@ -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; +} +```