From ba47331c409a231ddd420785c9af9604caf0f565 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 5 Oct 2023 09:27:25 +0200 Subject: [PATCH] vault backup: 2023-10-05 09:27:25 --- Prog/Loops.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) 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; +} +```