From 3a9475e302b24e866c71063dc93a359a63c2db88 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sun, 30 Jun 2024 21:35:18 +0800 Subject: [PATCH] Language Construct documentations for while, if-else, random, loop, unless, when, and maybe. --- site/constructs.pug | 107 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/site/constructs.pug b/site/constructs.pug index f3f3be3..01c1e71 100644 --- a/site/constructs.pug +++ b/site/constructs.pug @@ -176,6 +176,113 @@ html(lang="en") | render count + "\r\n"; | count = count + 1; | } while(count < 5); + br + + b(class="pb-2") While Expression + p While expressions execute a block of code as long as a condition is true. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_07.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Increment i variable using while + | + | i = 0; + | while(i < 10) { + | render i + "\r\n"; + | i = i + 1; + | }; + br + + b(class="pb-2") If-else Expression + p If expressions evaluate a condition and execute a block of code if the condition is true. Optionally, an else block can be provided for when the condition is false. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_08.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Checking x if positive or negative number with if-else + | + | x = 10; + | if(x > 0) + | render "x is a positive number" + | else render "x is a negative number"; + br + + b(class="pb-2") Random Expression + p Random expressions execute a block of code randomly, with an optional else block for when the condition is not met. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_09.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Execute a render expression randomly. + | + | random + | render "Randomly rendered string.\r\n" + | else render "Executing the else-clause.\r\n"; + br + + b(class="pb-2") Loop Expression + p Loop expressions define a traditional for-loop structure. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_10.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Loop expression example equivalent to for-loop in other languages. + | + | loop(i = 0; i < 10; i = i + 1) + | render i + "\r\n"; + br + + b(class="pb-2") Unless Expression + p Unless expressions execute a block of code if a condition is false, with an optional else block for when the condition is true. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_11.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Execute unless expression if x is not 0. + | + | x = 3.14; + | unless(x == 0) + | render "x is not zero.\r\n" + | else render "x is zero\r\n"; + + b(class="pb-2") When Expression + p When expressions are used for pattern matching and conditional execution based on multiple conditions. The concept for this expression is same as the switch statement on other programming languages such as C/C++, Java, or C#. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_12.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # When expression to render equivalent day for a number. + | + | day = 1; + | when(day) { + | if(0) render "Monday", + | if(1) render "Tuesday", + | if(2) render "Wednesday", + | if(3) render "Thursday", + | if(4) render "Friday", + | else render "Weekday" + | }; + br + + b(class="pb-2") Maybe Expression + p The maybe expression in Uartix is a boolean value. However, it only acquires a boolean value on runtime with either true or false randomly from the Raspberry Pi Pico. + + div(class="bg-primary w-100 mt-2") + p(class="text-white m-0 ms-2") example_13.utx + code(class="text-dark") + pre(class="border border-primary p-2") + | # Print a string if the maybe has a true value. + | + | should_print = maybe; + | if(should_print) + | render "Maybe had a true value." + | else render "Maybe had a false value."; div(class="col-lg-2")