From b4596a9d17adfc21e8a60c7191d9dbe0084e6104 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Mon, 10 Aug 2020 09:52:55 +0200 Subject: [PATCH] update --- docs/Reference/ControlFlow/ForLoop.mdr | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/Reference/ControlFlow/ForLoop.mdr 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 -- 2.43.0