calcium-lang
Version:
Calcium language interpreter
34 lines • 898 B
JavaScript
/**
* control a loop in runtime
*/
export default class LoopCounter {
constructor(start, stop, step = 1) {
this.start = start;
this.stop = stop;
this.step = step;
this.now = null;
}
next() {
if ((this.step > 0 && this.start >= this.stop) ||
(this.step < 0 && this.start <= this.stop)) {
return null;
}
else if (this.now === null) {
this.now = this.start;
return this.start;
}
else {
this.now += this.step;
if (this.step > 0) {
return this.now >= this.stop ? null : this.now;
}
else if (this.step < 0) {
return this.now <= this.stop ? null : this.now;
}
else {
return null;
}
}
}
}
//# sourceMappingURL=loopCounter.js.map