- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
type int = 1;
function makeRangeIterator(start = 0, end = 10000, step = 1) {
print("makeRangeIterator.");
let nextIndex = start;
let iterationCount = 0;
const rangeIterator = {
next() {
let result: [value: int, done: boolean];
if (nextIndex < end) {
result = [nextIndex, false];
nextIndex += step;
iterationCount++;
return result;
} else {
result = [iterationCount, true];
}
return result;
},
};
return rangeIterator;
}
function main() {
let it = makeRangeIterator(1, 10, 2);
let result = it.next();
while (!result.done) {
print(result.value); // 1 3 5 7 9
result = it.next();
}
print("done.");
}