forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrap.lcdoc
More file actions
58 lines (37 loc) · 1.42 KB
/
wrap.lcdoc
File metadata and controls
58 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Name: wrap
Type: operator
Syntax: <number> wrap <divisor>
Summary:
Wrap allows the user to ensure the value of a variable stays within a
specified range.
Introduced: 2.9
OS: mac, windows, linux, ios, android
Platforms: desktop, server, mobile
Example:
repeat with x = 1 to 10
put item x wrap 3 of "1,2,3" & comma after tOutput
end repeat
-- evaluates to 1,2,3,1,2,3,1,2,3,1
repeat with x=1 to 9
put item x wrap 2 of "1,2" & comma after tOutput
end repeat
--evaluates to 1,2,1,2,1,2,1,2,1
Parameters:
number:
divisor:
Description:
The wrap function makes it easy to loop successively over a fixed number
of items in a list. When cycling through the items of a list, the
divisor parameter specifies which item will cause the cycle to loop back
to the beginning of the list. This means that any number outside this
range is mapped to a number within it.
For example, if we had 5 wrap 3, the number 5 would be mapped to the
number 2 as this is where the iterator would be pointing on the 5th
iteration ie. 1, 2, 3, 1, 2 . Therefore 5 wrap 3 is 2.
The mathematical formula implemented by the wrap operator is:
x wraps y = ((x-1) mod abs(y)) +1 if (x >= 0)
= -((x-1) mod abs(y)) +1 if(x < 0)
If a math operation on finite inputs produces a non-finite output, an
execution error is thrown. See <math operation|math operations> for more
information.
References: / (operator), math operation (glossary)