@@ -8,40 +8,49 @@ until some condition is reached. Bellow are the loop types that abstract support
88
99---
1010## While loops
11- :::not-implemented
12- :::
1311
1412While loops are the most basic loop types. It while it conditional is valid or
1513the code reaches a breakpoint.
1614
17- This is the structure of a while syntax:
15+ These are the possibilities for the while statement syntax:
1816``` abs
19- while <condition> => <instruction>
17+ while <condition> do <instruction>
18+ while <condition> : <step> do <instruction>
19+ while <declaration> : <condition> : <step> do <instruction>
2020```
21+ ` declaration ` - Context variables that will be accessible inside the loop
22+ ` condition ` - The boolean value that will be tested before each iteration. The loop will continue running while this is true
23+ ` step ` - A process to be executed after each loop iteration
24+ ` instruction ` - what the loop should do every iteration
2125
22- While loops do not have iterators, so in this cse we must create our own:
23- ``` abs
24- let index = 10
25- while index > 0 => {
26+ While loops are the most common way to do repetitive tasks in Abstract. it behave both like while and for loops in
27+ the majority of other languages.
28+
29+ ``` c title="In C"
30+ for (var i = 0 ; i < 5 ; i++) {
31+ puts ("Hello, Scopped World!")
32+ }
33+ puts ("Loop break")
34+ ```
35+ ```abs title="In Abstract"
36+ while let i = 0 : index < 5 : i++ do {
2637 Std.Console.log("Hello, Scopped World!")
27- index -= 2
2838}
29- Std.Console.writeln(index )
39+ Std.Console.log("Loop break" )
3040```
3141``` text title="Console Output"
3242Hello, Scopped World!
3343Hello, Scopped World!
3444Hello, Scopped World!
3545Hello, Scopped World!
3646Hello, Scopped World!
37- 0
47+ Loop break
3848```
3949
40- Using a ` break ` statement, it is possible to stop the loop before it has reached
41- it condition:
50+ Using a ` break ` statement, it is possible to stop the loop before its condition fails:
4251``` abs
4352let index = 10
44- while index >= 0 => {
53+ while index >= 0 do {
4554 Std.Console.log("Hello, Scopped World!")
4655 index -= 2
4756
@@ -62,7 +71,7 @@ after each iteration:
6271``` abs
6372# Parenthesis are optional, but helps to read!
6473let index = 0
65- while (index < 10) : (index++) => Std.Console.log("Hello, World!")
74+ while (index < 10) : (index++) do Std.Console.log("Hello, World!")
6675```
6776
6877---
@@ -76,14 +85,14 @@ while (index < 10) : (index++) => Std.Console.log("Hello, World!")
7685from Std.Console import
7786
7887# Looping from 0 to 49
79- for i in ..50 => writeln(i)
88+ for i in ..50 do writeln(i)
8089
8190# Looping from 0 to 50 in steps of 10
82- for i in ..50:10 => writeln(i)
91+ for i in ..50:10 do writeln(i)
8392
8493# Looping though each element of a array
8594let []byte numbers = [22, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43]
86- for v in numbers => {
95+ for v in numbers do {
8796 write("Example of a prime number:")
8897 writeln(v)
8998}
0 commit comments