diff --git a/branches/Cargo.toml b/branches/Cargo.toml new file mode 100644 index 0000000..6934aa4 --- /dev/null +++ b/branches/Cargo.toml @@ -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] diff --git a/branches/src/main.rs b/branches/src/main.rs new file mode 100644 index 0000000..b04db10 --- /dev/null +++ b/branches/src/main.rs @@ -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)) +} diff --git a/comments/Cargo.toml b/comments/Cargo.toml new file mode 100644 index 0000000..476474d --- /dev/null +++ b/comments/Cargo.toml @@ -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] diff --git a/comments/src/main.rs b/comments/src/main.rs new file mode 100644 index 0000000..e10d362 --- /dev/null +++ b/comments/src/main.rs @@ -0,0 +1,8 @@ +fn main() { + // this is a comment + /* is this a comment? + * + * looks like it + */ + println!("Hello, world!"); +} diff --git a/notes b/notes index 4c39058..c724432 100644 --- a/notes +++ b/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