Rust for Beginner

This is just a post for the study of rust on Intro part.

Chap 1

Useful Tools

Chap 3

| int | unsigned int | float (IEEE 754) | | —- | ———— | —————- | | i8 | u8 | f32 | | i16 | u16 | f64 | | i32 | u32 | | | i64 | u64 | | | i128 | u128 | |

The function runs:

fn main() {
    another_function(5);
}

fn another_function(x: i32) {
    println!("The value of x is: {x}");
}
fn main() {
    let x = plus_one(5); // could this input variable? 

    println!("The value of x is: {x}");
}

fn plus_one(x: i32) -> i32 {
    x + 1
}
// The if statement to judge the number
fn main() {
    let number = 3;

    if number < 5 {
        println!("condition was true");
    } else {
        println!("condition was false");
    }
}
// A nested for loop example 
fn main() {
    let mut count = 0;
    'counting_up: loop {
        println!("count = {count}");
        let mut remaining = 10;

        loop {
            println!("remaining = {remaining}");
            if remaining == 9 {
                break;
            }
            if count == 2 {
                break 'counting_up; // break the outer loop
            }
            remaining -= 1;
        }
        count += 1;
    }
    println!("End count = {count}"); // 
}
// The result from a loop
fn main() {
    let mut counter = 0;

    let result = loop {
        counter += 1;

        if counter == 10 {
            break counter * 2;
        }
    };

    println!("The result is {result}"); // will give 20 
}