How to do it...

Follow these steps:

  1. Create a file named constant.rs with the next code snippet.
  1. Declare the global UPPERLIMIT using constant:
        // Global variables are declared outside scopes of other 
function
const UPPERLIMIT: i32 = 12;
  1. Create the is_big function by accepting a single integer as input:
        // function to check if bunber 
fn is_big(n: i32) -> bool {
// Access constant in some function
n > UPPERLIMIT
}
  1. In the main function, call the is_big function and perform the decision-making statement:
        fn main() {
let random_number = 15;

// Access constant in the main thread
println!("The threshold is {}", UPPERLIMIT);
println!("{} is {}", random_number, if
is_big(random_number) { "big" } else { "small"
});

// Error! Cannot modify a `const`.
// UPPERLIMIT = 5;

}

You should get the following screenshot as output upon running the preceding code:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.67.70