1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/test/test_while.coffee

54 lines
640 B
CoffeeScript
Raw Normal View History

2010-07-25 01:23:37 -04:00
i = 5
list = while i -= 1
i * 2
ok list.join(' ') is "8 6 4 2"
2010-07-25 01:23:37 -04:00
i = 5
list = (i * 3 while i -= 1)
ok list.join(' ') is "12 9 6 3"
2010-07-25 01:23:37 -04:00
i = 5
func = (num) -> i -= num
assert = -> ok i < 5 > 0
2010-07-25 01:23:37 -04:00
results = while func 1
assert()
i
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
i * 2
ok results.join(' ') is '16 12 8 4'
2010-07-25 01:23:37 -04:00
value = false
i = 0
results = until value
value = true if i is 5
i += 1
ok i is 6
# And, the loop form of while.
2010-07-25 01:23:37 -04:00
i = 5
list = []
loop
2010-07-25 01:23:37 -04:00
i -= 1
break if i is 0
list.push i * 2
ok list.join(' ') is '8 6 4 2'
#759: `if` within `while` condition
2 while if 1 then 0