You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Help/loops.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
Loops
2
2
---
3
3
4
-
To repeat an instruction (or sequence of instructions) you can use a `for` loop. The simplest form of the for loop takes a numeric range, and a block of instructions inside braces. The following loop creates a circle of 5 points (you might use this inside a `path`):
4
+
To repeat an instruction (or sequence of instructions) you can use a `for` loop. The simplest form of the for loop takes a [numeric range](expressions.md#ranges), and a block of instructions inside braces. The following loop creates a circle of 5 points (you might use this inside a `path`):
5
5
6
6
```swift
7
7
for1 to 5 {
@@ -12,7 +12,7 @@ for 1 to 5 {
12
12
13
13
The range `1 to 5` is inclusive of both the start and end values. A range of `0 to 5` would therefore loop *6* times and not 5 as you might expect.
14
14
15
-
The loop count does not have to be a literal value, you can use a previously defined symbol or expression instead:
15
+
The loop range does not have to be a literal value, you can use a previously defined symbol or expression instead:
16
16
17
17
```swift
18
18
define count 5
@@ -23,7 +23,7 @@ for 1 to count {
23
23
}
24
24
```
25
25
26
-
If you have used similar loops in other programming languages, you might be wondering why we don't need to use an index variable of some kind to keep track of the loop iteration.
26
+
If you have used similar loops in other programming languages, you might be wondering why we don't need to use an index variable of some kind to keep track of the loop iteration?
27
27
28
28
Symbols defined inside the `{ ... }` block will not persist between loops (see [scope](scope.md) for details), but changes to the world transform will, which is why the `rotate` command doesn't need to reference the index - its effect is cumulative.
29
29
@@ -37,7 +37,7 @@ for i in 1 to count {
37
37
38
38
This defines a [symbol](symbols.md) called `i` with the value of the current loop iteration. The `i` symbol only exists within the loop body itself and can't be referenced after the loop has ended.
39
39
40
-
(**Note:** The index symbol does not need to be called `i`, it can be any valid symbol name that you choose.)
40
+
**Note:** The index symbol does not need to be called `i`, it can be any valid symbol name that you choose.
0 commit comments