Skip to main content

rl_lang/docs/entries/tutorial/t1/
p5.rs

1use crate::docs::entry::{ConceptCategory, ConceptEntry, DescriptionEntry, DescriptionKind};
2pub static STEP_OPERATORS_AND_DECISIONS: ConceptEntry = ConceptEntry {
3    name: "5. making decisions",
4    summary: "making decisions",
5    category: ConceptCategory::ControlFlow,
6    prerequisites: &[],
7    descriptions: &[
8        DescriptionEntry {
9            kind: DescriptionKind::Explanation,
10            title: None,
11            description: "comparison operators compare two values and produce a bool. you use these to ask questions about your data",
12            examples: &[
13                "println(5 == 5)   // true  (equal)\nprintln(5 != 3)   // true  (not equal)\nprintln(3 < 10)   // true  (less than)\nprintln(10 > 3)   // true  (greater than)\nprintln(3 <= 3)   // true  (less than or equal)\nprintln(10 >= 10) // true  (greater than or equal)",
14            ],
15            expected_output: &[],
16        },
17        DescriptionEntry {
18            kind: DescriptionKind::Explanation,
19            title: None,
20            description: "if runs a block of code only when a condition is true. else runs when it is false. you can chain as many else if branches as you need",
21            examples: &[
22                "dec int score = 75\n\nif (score >= 90) {\n    println(\"excellent\")\n} else if (score >= 60) {\n    println(\"good\")\n} else {\n    println(\"keep trying\")\n}",
23            ],
24            expected_output: &[],
25        },
26        DescriptionEntry {
27            kind: DescriptionKind::Explanation,
28            title: None,
29            description: "! flips a bool. true becomes false, false becomes true",
30            examples: &[
31                "dec bool ready = false\n\nif (!ready) {\n    println(\"not ready yet\")\n}",
32            ],
33            expected_output: &[],
34        },
35        DescriptionEntry {
36            kind: DescriptionKind::Explanation,
37            title: None,
38            description: "arithmetic works as you expect. parentheses control the order of evaluation",
39            examples: &[
40                "dec int a = (2 + 3) * 4  // 20\ndec int b = 2 + 3 * 4    // 14 (multiplication first)\ndec int c = 10 / 2       // 5",
41            ],
42            expected_output: &[],
43        },
44        DescriptionEntry {
45            kind: DescriptionKind::Explanation,
46            title: None,
47            description: "exercise: add a guess check to your game. compare the guess to the secret number (still hardcoded as 42) and tell the player if they guessed too low, too high, or correctly\n\nexpected output (if guess is 30):\n  enter your guess: 30\n  too low!\n\nexpected output (if guess is 42):\n  enter your guess: 42\n  correct!",
48            examples: &[
49                "get read_int from std::io\nget concat   from std::str\n\ndec int secret = 42\ndec int guess  = read_int(\"enter your guess: \")\n\nif (guess < secret) {\n    println(\"too low!\")\n} else if (guess > secret) {\n    println(\"too high!\")\n} else {\n    println(\"correct!\")\n}",
50            ],
51            expected_output: &[],
52        },
53    ],
54    pitfalls: &[],
55    related: &[],
56    related_stdlib: &[],
57    since: None,
58};