From: Jérémie Astor Date: Mon, 10 Aug 2020 07:52:55 +0000 (+0200) Subject: update X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=b4596a9d17adfc21e8a60c7191d9dbe0084e6104;p=gwion.git update --- diff --git a/docs/Reference/ControlFlow/ForLoop.mdr b/docs/Reference/ControlFlow/ForLoop.mdr new file mode 100644 index 00000000..345bdf71 --- /dev/null +++ b/docs/Reference/ControlFlow/ForLoop.mdr @@ -0,0 +1,62 @@ +# For Loops +**For** loops in Gwion is pretty similar to classic **C** syntax + +## basic loops +@``` forloop0.gw +for(int i; i < 3; ++i) + <<< i >>>; +@``` +@hide make -s forloop0.test + +It also works with a block of code. + +@``` forloop2.gw +for(int i; i < 3; ++i) { + i/2 => float f1; + i/2. => float f2; + <<< i, " " , f1, " ", f2 >>>; +} +@``` +@hide make -s forloop2.test + +## Nested Loops +@``` forloop3.gw +int array[3][4]; + +for(int i; i < 3; ++i) { + for(int j; j < 4; ++j) { + <<< array[i][j] >>>; + } +} +@``` +@hide make -s forloop3.test + +### Auto Loops + +#### Simple auto loop +@``` forloop4.gw +int array[2][3]; +for(auto a: array) { + <<< a >>>; + for(auto b: a) + <<< b >>>; +} +@``` +@hide make -s forloop4.test + +### Auto Pointer loop +If you want to change it the value in the array, you need a pointer + +@``` forloop5.gw +int array[2][3]; +int i; +for(auto a: array) { + for(auto ref b: a) + <<< ++i => *b >>>; +} +for(auto a: array) { + for(auto ref b: a) + <<< *b >>>; +} +@``` +@hide make -s forloop5.test