Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / base_for_finish.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import array
16
17 class MyC
18 var data: Collection[Object]
19 fun iterator: MyI do return new MyI(data.iterator)
20 end
21
22 class MyI
23 super Iterator[Object]
24 var iter: Iterator[Object]
25 redef fun is_ok do return iter.is_ok
26 redef fun item do return iter.item
27 redef fun next do iter.next
28 redef fun finish do 0.output
29 end
30
31 fun test(a: MyC)
32 do
33 for x in a do
34 x.output
35 for y in [10,20] do
36 y.output
37 if x == 2 then return
38 end
39 100.output
40 end
41 200.output
42 end
43
44 var a = new MyC([1,2,3])
45
46 for x in a do
47 x.output
48 end
49
50 '\n'.output
51
52 for x in a do
53 x.output
54 if x == 2 then break
55 100.output
56 end
57
58 '\n'.output
59
60 test(a)