mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Tweaked syntax highlighting, added control flow to docs
I also found some issues in the code, so I fixed them first.
This commit is contained in:
@@ -66,14 +66,53 @@ The usable types are as follows:
|
|||||||
|
|
||||||
## Control Flow
|
## 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
|
```toy
|
||||||
for //not yet implemented
|
var challenge = "hard";
|
||||||
continue
|
|
||||||
break
|
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
|
## Functions
|
||||||
|
|||||||
7
_includes/styles/toylang-syntax.css
Normal file
7
_includes/styles/toylang-syntax.css
Normal file
@@ -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%;
|
||||||
|
}
|
||||||
@@ -55,5 +55,6 @@ theme_url: https://github.com/pixeldroid/programming-pages
|
|||||||
{% include scripts/help.js %}
|
{% include scripts/help.js %}
|
||||||
|
|
||||||
{% comment %} provide user extension / override point {% endcomment %}
|
{% comment %} provide user extension / override point {% endcomment %}
|
||||||
|
{% include scripts/toylang-syntax.js %}
|
||||||
{% include scripts/custom.js %}
|
{% include scripts/custom.js %}
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user