rl_lang/docs/entries/concepts/flow_control/
mod.rs1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2
3pub static CONTROL_FLOW: ConceptEntry = ConceptEntry {
4 name: "control flow",
5 descriptions: &[
6 DescriptionEntry {
7 description: "`if` runs a block when the condition is true",
8 examples: &["dec int x = 10\n\nif (x > 5) {\n println(\"big\")\n}"],
9 kind: DescriptionKind::Explanation,
10 title: None,
11 expected_output: &[],
12 },
13 DescriptionEntry {
14 description: "`else if` and `else` add additional branches",
15 examples: &[
16 "dec int x = 5\n\nif (x > 10) {\n println(\"big\")\n} else if (x == 5) {\n println(\"five\")\n} else {\n println(\"small\")\n}",
17 ],
18 kind: DescriptionKind::Explanation,
19 title: None,
20 expected_output: &[],
21 },
22 DescriptionEntry {
23 description: "`while` loops as long as the condition is true",
24 examples: &["dec int i = 0\n\nwhile (i < 5) {\n println(i)\n i += 1\n}"],
25 kind: DescriptionKind::Explanation,
26 title: None,
27 expected_output: &[],
28 },
29 DescriptionEntry {
30 description: "`break` exits a loop early, `continue` skips to the next iteration",
31 examples: &[
32 "dec int i = 0\nwhile (true) {\n if (i == 3) { break }\n i += 1\n}",
33 "dec int i = 0\nwhile (i < 5) {\n i += 1\n if (i == 3) { continue }\n println(i) // prints 1, 2, 4, 5\n}",
34 ],
35 kind: DescriptionKind::Explanation,
36 title: None,
37 expected_output: &[],
38 },
39 ],
40 summary: "",
41 category: ConceptCategory::Syntax,
42 prerequisites: &[],
43 pitfalls: &[],
44 related: &[],
45 related_stdlib: &[],
46 since: None,
47};
48
49pub static FOR_LOOPS: ConceptEntry = ConceptEntry {
50 name: "for loops",
51 descriptions: &[
52 DescriptionEntry {
53 description: "C-style for loop: `for [<type> <var> = <init>, <condition>, <increment>] { }`",
54 examples: &["for [int i = 0, i < 5, i += 1] {\n println(i)\n}"],
55 kind: DescriptionKind::Explanation,
56 title: None,
57 expected_output: &[],
58 },
59 DescriptionEntry {
60 description: "range-based for loop iterates from start to end (exclusive): `for <var> in <start>..<end>`",
61 examples: &["for i in 0..5 {\n println(i) // 0 1 2 3 4\n}"],
62 kind: DescriptionKind::Explanation,
63 title: None,
64 expected_output: &[],
65 },
66 DescriptionEntry {
67 description: "iterate over an inline array literal",
68 examples: &["for x in [10, 20, 30] {\n println(x)\n}"],
69 kind: DescriptionKind::Explanation,
70 title: None,
71 expected_output: &[],
72 },
73 DescriptionEntry {
74 description: "iterate over an array variable with `for <var> in <array>`",
75 examples: &[
76 "dec arr[string] names = [\"ali\", \"bob\", \"carl\"]\n\nfor name in names {\n println(name)\n}",
77 ],
78 kind: DescriptionKind::Explanation,
79 title: None,
80 expected_output: &[],
81 },
82 ],
83 summary: "",
84 category: ConceptCategory::Syntax,
85 prerequisites: &[],
86 pitfalls: &[],
87 related: &[],
88 related_stdlib: &[],
89 since: None,
90};