comments, flow control
This commit is contained in:
parent
6db7d9edf7
commit
9a7a9558b5
8
branches/Cargo.toml
Normal file
8
branches/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "branches"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
20
branches/src/main.rs
Normal file
20
branches/src/main.rs
Normal file
@ -0,0 +1,20 @@
|
||||
fn main() {
|
||||
let number = 3;
|
||||
let b = if number < 5 { "duh" } else { "blwewew" };
|
||||
println!("{number} {b}");
|
||||
|
||||
let mut x = 0.0;
|
||||
let mut y = 0.0;
|
||||
let q = 'outer: loop {
|
||||
x += 0.1;
|
||||
loop {
|
||||
y += 0.1;
|
||||
if y > 2.0 {
|
||||
break 'outer y
|
||||
}
|
||||
println!("x: {}, y: {}", x, y);
|
||||
}
|
||||
};
|
||||
println!("y: {q}");
|
||||
println!((1..4))
|
||||
}
|
8
comments/Cargo.toml
Normal file
8
comments/Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "comments"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
8
comments/src/main.rs
Normal file
8
comments/src/main.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
// this is a comment
|
||||
/* is this a comment?
|
||||
*
|
||||
* looks like it
|
||||
*/
|
||||
println!("Hello, world!");
|
||||
}
|
57
notes
57
notes
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user