mirror of https://github.com/japl-lang/japl.git
89 lines
1.1 KiB
Plaintext
89 lines
1.1 KiB
Plaintext
//[Test: forwithfunction]
|
|
//[skip]
|
|
//[source: mixed]
|
|
var y = 0; //a global to keep track of state
|
|
//does not need closures for this to work yet
|
|
|
|
fun next(x) {
|
|
if (x == 0) {
|
|
y = y + 1;
|
|
x = 0;
|
|
}
|
|
if (y == 10)
|
|
return -1;
|
|
return x+y+1;
|
|
}
|
|
|
|
for (var i = 0; i != -1; i = next(i))
|
|
print(i);
|
|
// before using next
|
|
//stdout:0
|
|
// y = 0
|
|
//stdout:1
|
|
//stdout:2
|
|
//stdout:3
|
|
//stdout:4
|
|
//stdout:5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 1
|
|
//stdout:2
|
|
//stdout:3
|
|
//stdout:4
|
|
//stdout:5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 2
|
|
//stdout:3
|
|
//stdout:4
|
|
//stdout:5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 3
|
|
//stdout:4
|
|
//stdout:5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 4
|
|
//stdout:5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 5
|
|
//stdout:6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 6
|
|
//stdout:7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 7
|
|
//stdout:8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 8
|
|
//stdout:9
|
|
//stdout:10
|
|
// y = 9
|
|
//stdout:10
|
|
// y = 10
|
|
//[end]
|
|
//[end]
|