diff --git a/_getting_started/quick-start-guide.md b/_getting_started/quick-start-guide.md index 01825f8..b871423 100644 --- a/_getting_started/quick-start-guide.md +++ b/_getting_started/quick-start-guide.md @@ -66,14 +66,53 @@ The usable types are as follows: ## Control Flow -Watch this space. +Performing different actions, or repeating an action multiple times, is essential for any general purpose language. +Choosing between two options can be done with the `if-then-else` else statement. If the condition is 'truthy', the 'then-branch' will be executed. If the condition is not truthy, the optional 'else-branch' is executed instead. + +```toy +var answer = 42; + +if (answer < 56) { + print "Success"; +} +else { + print "Something's fishy here..."; +} ``` -if-then-else -while -for //not yet implemented -continue -break + +```toy +var challenge = "hard"; + +if (challenge == "hard") { + print "I choose to build a scripting language, not because it's easy, but because it's hard!"; +} + +//the else-branch is optional +``` + +To repeat a certain action, use the `while-then` loop, which repeats the body as long as the condition is true at the beginning of each loop. + +```toy +var loops = 0; + +while (loops++ < 8) { + print "These episodes are endless."; +} +``` + +To break out of a loop, you can use the `break` keyword. Alternatively, to restart the loop early, use the `continue` keyword. + +```toy +var loops = 0; + +while (true) { + if (++loops < 15532) { + continue; + } + + break; //poor yuki ;_; +} ``` ## Functions diff --git a/_includes/styles/toylang-syntax.css b/_includes/styles/toylang-syntax.css new file mode 100644 index 0000000..5b536f3 --- /dev/null +++ b/_includes/styles/toylang-syntax.css @@ -0,0 +1,7 @@ +/* copied from the main theme */ +pre:has(> code.language-toy) { + line-height: 1.18em; + overflow-x: auto; + width: fit-content; + max-width: 100%; +} diff --git a/_layouts/page.html b/_layouts/page.html index 0cfa924..1399416 100644 --- a/_layouts/page.html +++ b/_layouts/page.html @@ -55,5 +55,6 @@ theme_url: https://github.com/pixeldroid/programming-pages {% include scripts/help.js %} {% comment %} provide user extension / override point {% endcomment %} +{% include scripts/toylang-syntax.js %} {% include scripts/custom.js %} \ No newline at end of file