This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn give_me_your_name(name: &String) { | |
println!("Look at me, this is my name now! {}", name) | |
} | |
fn main() { | |
let my_name = String::from("Jeff"); | |
give_me_your_name(&my_name); | |
println!("Not it is not, it still my name: {}", my_name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn give_me_your_name(name: String) { | |
println!("Look at me, this is my name now! {}", name); | |
} | |
fn main() { | |
let my_name = String::from("Jeff"); | |
give_me_your_name(my_name); | |
// Uncomment the next line and its gonna give you an error | |
// println!("This was my name: {}, my_name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myName = { name: "Jeff" }; | |
const sameName = myName; | |
sameName.name += " C."; | |
console.log("My name is", myName.name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let my_name = String::from("Jeff"); | |
let same_name = my_name; | |
println!("My name is {}", same_name); | |
// println!("My name is {}", my_name); // This is not going to work | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let my_name = String::from("Jeff"); | |
println!("My name is {}", my_name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn another_sum(x: i32, y:i32) -> i32 { | |
x + y | |
} | |
fn sum(x:i32, y:i32) -> i32 { | |
return x + y; | |
} | |
fn main() { | |
println!("{}", sum(5, 8)); | |
println!("{}", another_sum(9, 12)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn print_my_number(i: i32) { | |
println!("The value that you sent is: {}", i); | |
} | |
fn main() { | |
let i = 42; | |
print_my_number(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut i = 0; | |
loop { | |
println!("Is this going to print for eternity?"); | |
i += 1; | |
if i == 42 { | |
println!("Of course not. We have the answer"); | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let bands = vec!["Rush", "Black Sabbath", "Pink Floyd"]; | |
for band in bands.iter() { | |
println!("{} is one of my favorite bands", band); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
for n in 1..8 { | |
println!("Your number is: {}", n + 5); | |
} | |
for n in 1..=8 { | |
println!("Your number is: {}", n + 5); | |
} | |
} |
NewerOlder