Last change
on this file was 439, checked in by coas-nagasima, 4 years ago |
mrubyを2.1.1に更新
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby;charset=UTF-8
|
File size:
954 bytes
|
Rev | Line | |
---|
[439] | 1 | assert('while expression', '11.5.2.3.2') do
|
---|
| 2 | idx = 10
|
---|
| 3 | all = []
|
---|
| 4 | res = while idx > 0
|
---|
| 5 | all << idx
|
---|
| 6 | idx -= 1
|
---|
| 7 | end
|
---|
| 8 |
|
---|
| 9 | assert_equal nil, res
|
---|
| 10 | assert_equal [10,9,8,7,6,5,4,3,2,1], all
|
---|
| 11 | end
|
---|
| 12 |
|
---|
| 13 | assert('until expression', '11.5.2.3.3') do
|
---|
| 14 | idx = 10
|
---|
| 15 | all = []
|
---|
| 16 | res = until idx == 0
|
---|
| 17 | all << idx
|
---|
| 18 | idx -= 1
|
---|
| 19 | end
|
---|
| 20 |
|
---|
| 21 | assert_equal nil, res
|
---|
| 22 | assert_equal [10,9,8,7,6,5,4,3,2,1], all
|
---|
| 23 | end
|
---|
| 24 |
|
---|
| 25 | assert('break expression', '11.5.2.4.3') do
|
---|
| 26 | assert_equal :result do
|
---|
| 27 | while true
|
---|
| 28 | break :result
|
---|
| 29 | end
|
---|
| 30 | end
|
---|
| 31 |
|
---|
| 32 | assert_equal :result do
|
---|
| 33 | until false
|
---|
| 34 | break :result
|
---|
| 35 | end
|
---|
| 36 | end
|
---|
| 37 | end
|
---|
| 38 |
|
---|
| 39 | assert('next expression', '11.5.2.4.4') do
|
---|
| 40 | assert_equal [8,6,4,2,0] do
|
---|
| 41 | all = []
|
---|
| 42 | idx = 10
|
---|
| 43 | while idx > 0
|
---|
| 44 | idx -= 1
|
---|
| 45 | next if (idx % 2) == 1
|
---|
| 46 | all << idx
|
---|
| 47 | end
|
---|
| 48 | all
|
---|
| 49 | end
|
---|
| 50 |
|
---|
| 51 | assert_equal [8,6,4,2,0] do
|
---|
| 52 | all = []
|
---|
| 53 | idx = 10
|
---|
| 54 | until idx == 0
|
---|
| 55 | idx -= 1
|
---|
| 56 | next if (idx % 2) == 1
|
---|
| 57 | all << idx
|
---|
| 58 | end
|
---|
| 59 | all
|
---|
| 60 | end
|
---|
| 61 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.