mirror of https://git.sr.ht/~garritfra/sabre
Garrit Franke
3 years ago
5 changed files with 46 additions and 7 deletions
@ -0,0 +1,5 @@
|
||||
# Common language concepts |
||||
|
||||
This chapter covers concepts that appear in almost every programming language and how they work in Rust. Many programming languages have much in common at their core. |
||||
|
||||
Specifically, you’ll learn about variables, basic types, functions, comments, and control flow. These foundations will be in every Sabre program, and learning them early will give you a strong core to start from. |
@ -0,0 +1,22 @@
|
||||
# Variables |
||||
|
||||
If you are familiar with some other programming language, the way Sabre handles variables won't surprise you. |
||||
|
||||
To declare a variable, the `let` keyword is used. |
||||
|
||||
``` |
||||
// variables.sb |
||||
fn main() { |
||||
let x = 10 |
||||
let y = 5 |
||||
return x + y |
||||
} |
||||
``` |
||||
|
||||
Run this code using the sabre CLI: |
||||
|
||||
``` |
||||
$ sabre build variables.sb -o variables.js |
||||
$ node variables.js |
||||
15 |
||||
``` |
@ -1,8 +1,4 @@
|
||||
fn main() { |
||||
let x = true && false |
||||
let y = false && true || true |
||||
let z = x && true |
||||
while true && x { |
||||
return x |
||||
} |
||||
} |
||||
let x = 10 |
||||
return x + 10 |
||||
} |
||||
|
Loading…
Reference in new issue