Using If-else Expression in Rust
📖 Scenario: You are creating a simple program that decides if a number is positive or not. This is like checking if the temperature is above zero to decide if you need a jacket.
🎯 Goal: Build a Rust program that uses an if-else expression to check if a number is positive and prints the result.
📋 What You'll Learn
Create a variable called
number with the value 10Create a variable called
result that uses an if-else expression to check if number is greater than 0If
number is greater than 0, result should be the string "Positive"Otherwise,
result should be the string "Not positive"Print the value of
result💡 Why This Matters
🌍 Real World
If-else expressions are used in many programs to make decisions, like checking if a user is logged in or if a payment is successful.
💼 Career
Understanding if-else expressions is essential for writing clear and efficient code in Rust and many other programming languages.
Progress0 / 4 steps