2010-07-25 01:23:37 -04:00
|
|
|
i = 5
|
|
|
|
list = while i -= 1
|
2010-01-13 21:27:22 -05:00
|
|
|
i * 2
|
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok list.join(' ') is "8 6 4 2"
|
2010-01-13 21:27:22 -05:00
|
|
|
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
i = 5
|
|
|
|
list = (i * 3 while i -= 1)
|
2010-01-13 21:27:22 -05:00
|
|
|
|
2010-02-16 19:45:25 -05:00
|
|
|
ok list.join(' ') is "12 9 6 3"
|
2010-02-15 23:05:54 -05:00
|
|
|
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
i = 5
|
|
|
|
func = (num) -> i -= num
|
|
|
|
assert = -> ok i < 5 > 0
|
2010-02-15 23:05:54 -05:00
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
results = while func 1
|
2010-02-15 23:05:54 -05:00
|
|
|
assert()
|
|
|
|
i
|
|
|
|
|
2010-02-23 22:53:43 -05:00
|
|
|
ok results.join(' ') is '4 3 2 1'
|
|
|
|
|
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
i = 10
|
|
|
|
results = while i -= 1 when i % 2 is 0
|
2010-02-23 22:53:43 -05:00
|
|
|
i * 2
|
|
|
|
|
|
|
|
ok results.join(' ') is '16 12 8 4'
|
|
|
|
|
2010-04-28 22:08:00 -04:00
|
|
|
|
2010-07-25 01:23:37 -04:00
|
|
|
value = false
|
|
|
|
i = 0
|
|
|
|
results = until value
|
|
|
|
value = true if i is 5
|
2010-04-28 22:08:00 -04:00
|
|
|
i += 1
|
|
|
|
|
|
|
|
ok i is 6
|
2010-06-12 12:15:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
# And, the loop form of while.
|
2010-07-25 01:23:37 -04:00
|
|
|
i = 5
|
|
|
|
list = []
|
2010-06-12 12:15:53 -04:00
|
|
|
loop
|
2010-07-25 01:23:37 -04:00
|
|
|
i -= 1
|
2010-06-12 12:15:53 -04:00
|
|
|
break if i is 0
|
|
|
|
list.push i * 2
|
|
|
|
|
|
|
|
ok list.join(' ') is '8 6 4 2'
|
2010-10-11 07:29:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
#759: `if` within `while` condition
|
|
|
|
2 while if 1 then 0
|