| 1 | struct CustomIter { |
| 2 | mut: |
| 3 | idx int |
| 4 | } |
| 5 | |
| 6 | fn new_custom_iter() CustomIter { |
| 7 | return CustomIter{ |
| 8 | idx: 0 |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | fn (mut a CustomIter) next() ?int { |
| 13 | if a.idx == 4 { |
| 14 | return none |
| 15 | } else { |
| 16 | a.idx++ |
| 17 | return a.idx * 2 |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | for x in new_custom_iter() { |
| 23 | println('a.${x}') |
| 24 | } |
| 25 | for ix, val in new_custom_iter() { |
| 26 | println('b.${ix}=${val}') |
| 27 | } |
| 28 | println('end') |
| 29 | } |
| 30 |