comments, flow control

This commit is contained in:
2022-12-16 10:00:30 -05:00
parent 6db7d9edf7
commit 9a7a9558b5
5 changed files with 101 additions and 0 deletions

57
notes
View File

@ -80,4 +80,61 @@ Arrays:
let first = a[0];
they are allocated on stack
https://doc.rust-lang.org/book/ch03-03-how-functions-work.html
all function parameters must be annotated
functions consist of statements and expressions
statements perform an action and have no return value
expressions do return something
a scope block is an expression
expressions do not end with a ";", if you add a ";" it will be statement
return is explicit if the last statement in a function is an expression
https://doc.rust-lang.org/book/ch03-04-comments.html
comments
// is a comment
/* is also a comment
b*/
for some reason the doc didn't mention the second type..
https://doc.rust-lang.org/book/ch03-05-control-flow.html
control flow
there is `if``
block of code within the "if" are _arms_.
just like the match
if must recieve a bool
no bad python
if num {}
if (thing) {
else if (other thing) {
} else if (yat) {
} else {
}
use `match` for too many else ifs
if is an expression!
you can loop with `loop`
loop is an expression!
break can return a value (not for for loops though they are a statement)
break can select nest level with 'label
thats called a loop label
while loop exists
for loop exists
syntax: for x in y {}
(start..end) is a Range
(1..4).rev() is a thing