Using if as expression
๐ Scenario: You are building a simple program to decide if a person is an adult or a minor based on their age.
๐ฏ Goal: Create a Rust program that uses if as an expression to assign a message depending on the age.
๐ What You'll Learn
Create a variable
age with the value 20Create a variable
status that uses if as an expression to assign "Adult" if age is 18 or more, otherwise "Minor"Print the
status variable๐ก Why This Matters
๐ Real World
Using <code>if</code> as an expression helps write concise code for decisions like checking age limits.
๐ผ Career
Understanding expressions and conditional assignments is important for writing clean and efficient Rust code in real projects.
Progress0 / 4 steps