docs about loops and functions

This commit is contained in:
cozis
2022-08-18 15:53:19 +02:00
parent 2da122a5ab
commit 449c2073a7
4 changed files with 278 additions and 6 deletions
+17 -1
View File
@@ -9,6 +9,7 @@ if condition: {
# Executed when the condition is false
}
```
Unlike expressions statements, they don't end with a `;`.
The condition may be any type of expression, but must evaluate to a boolean type. No implicit casts are performed.
@@ -55,4 +56,19 @@ creating a chain of if-else statements.
## Compound statements
Actually the meaning of the curly brackets is to group multiple statements into one.
The if-else statement expects only one statement for each branch, though it's possible to provide more than one statement each by wrapping them into curly brackets.
The if-else statement expects only one statement for each branch, though it's possible to provide more than one statement each by wrapping them into curly brackets.
## Scopes
If-else and compound statements don't create new scopes, which means that variables defined inside one of those statements will be accessible outside of them:
```py
if 1 < 2:
a = 10;
# Here "a" is still defined.
print(a); # Prints 10
```
```py
{
a = 1;
}
print(a); # Prints 1
```