1
0
Fork 0
forked from fun/fun

While loops.

This commit is contained in:
Johannes Findeisen 2025-09-14 15:40:09 +02:00
commit 24305209eb
3 changed files with 94 additions and 2 deletions

35
examples/while_test.fun Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env fun
// While loops feature test: simple loops, nested with if/else, and functions
print("=== while test start ===")
// Simple counter 0..4
number i = 0
while (i < 5)
print(i) // expect 0,1,2,3,4
i = i + 1
// Nested while with if/else
number a = 3
while (a > 0)
if (a == 2)
print(99) // special case when a == 2
else
print(a)
a = a - 1 // expect: 3, 99, 1
// While with false condition: body should not run
while (0)
print(123)
// Function using while
fun countdown(n)
while (n > 0)
print(n)
n = n - 1
return 0
print(countdown(3)) // expect: 3,2,1 then 0
print("=== while test end ===")