-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
53 lines (39 loc) · 1.03 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn main() {
println!("Hello, world!");
another_function(5);
print_labeled_measurement(7, 'm');
// Expressions
// expressions do not have semicolons
let y = {
let x = 3;
x+1
};
println!("The value of y is: {y}");
let x = five();
println!("The value of x is: {x}");
let z = plus_one(8);
println!("The value of z is: {z}");
let someNumEven: bool = is_even(9);
println!("Is 9 even? {someNumEven}");
}
fn another_function(x:i32) {
println!("The value of x is {x}");
}
fn print_labeled_measurement(value: i32, label: char){
println!("The measurement is {value}{label}");
}
// Even though this func only contains the number 5, it is still perfectly legal. (even its return type is i32)
fn five() -> i32 {
5 // 5 is an expression because it doesn't have a semicolon and this is the expression we want to return.
}
fn plus_one(x: i32) -> i32 {
x+1
}
fn is_even(x:i32) -> bool {
if x % 2 == 0 {
return true;
}
else {
return false;
}
}