-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.lux
More file actions
51 lines (44 loc) · 1.03 KB
/
loop.lux
File metadata and controls
51 lines (44 loc) · 1.03 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
[doc Demo the loop statement]
[global file=loop_break.tmp]
###
### Vanilla style of loops
###
[shell vanilla]
# Iterate over a fix list of items
[loop color green yellow red]
!echo "Color $color"
?SH-PROMPT:
[endloop]
# Iterate over a range
[loop i 1..5]
!echo "Iter $i"
?SH-PROMPT:
[endloop]
# Iterate over a mix of strings, reverse range and range with custom incr
[local colors=green yellow red]
[local incr=3]
[loop mix $color 7..4 3..9..$incr]
!echo "Mix $mix"
?SH-PROMPT:
[endloop]
###
### Loop with break patterns
###
[shell background]
# Setup a background job which eventually adds DONE to a file
!echo foo > $file;
?SH-PROMPT:
!(sleep 3; echo DONE >> $file)
[shell foreground]
# Probe the file for the DONE string using a break pattern
[loop i 1..7]
@DONE
[progress i=$i]
!cat $file
?SH-PROMPT:
[sleep 1]
[endloop]
?SH-PROMPT:
[cleanup]
!rm -f $file
?SH-PROMPT: