-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops_break_continue.fun
More file actions
executable file
·66 lines (59 loc) · 1.1 KB
/
loops_break_continue.fun
File metadata and controls
executable file
·66 lines (59 loc) · 1.1 KB
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
62
63
64
65
66
#!/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
*/
/*
* Loop Control Flow Examples
*
* Focuses on:
* - Using break to exit loops prematurely
* - Implementing continue for skipping iterations
* - Creating complex loop control patterns
* - Handling infinite loops and their termination conditions
*/
// break and continue examples
// 1) while loop: print odd numbers, stop after printing 7
number i = 0
while i < 10
if i % 2 == 0
i = i + 1
continue
print(i) // -> 1, 3, 5, 7
if i > 5
break
i = i + 1
// 2) for range: skip 3, stop at 6
for i in range(0, 8)
if i == 3
continue
print(i) // -> 0, 1, 2, 4, 5, 6
if i == 6
break
// 3) for-in over array: skip 3, break at 4
arr = [1, 2, 3, 4, 5]
for x in arr
if x == 3
continue
print(x) // -> 1, 2, 4
if x == 4
break
/* Expected output:
1
3
5
7
0
1
2
4
5
6
1
2
4
*/