-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhile_test.fun
More file actions
executable file
·62 lines (51 loc) · 999 Bytes
/
while_test.fun
File metadata and controls
executable file
·62 lines (51 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env fun
/*
* This file is part of the Fun programming language.
* https://fun-lang.xyz/
*
* Copyright 2025 Johannes Findeisen <you@hanez.org>
* Licensed under the terms of the Apache-2.0 license.
* https://opensource.org/license/apache-2-0
*/
// 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 ===")
/* Expected output:
=== while test start ===
0
1
2
3
4
3
99
1
3
2
1
0
=== while test end ===
*/