Using If Expression in Rust
๐ Scenario: Imagine you are building a simple program that decides if a person is old enough to vote. Voting age is 18 years or older.
๐ฏ Goal: You will create a program that uses an if expression to check a person's age and print whether they can vote or not.
๐ What You'll Learn
Create a variable called
age with the value 20Create a variable called
voting_eligibility that uses an if expression to check if age is 18 or moreUse
if expression to assign "Can vote" if age is 18 or more, otherwise "Cannot vote"Print the value of
voting_eligibility๐ก Why This Matters
๐ Real World
Checking conditions like age eligibility is common in many programs, such as voting systems, age-restricted content, or membership access.
๐ผ Career
Understanding if expressions is fundamental for decision-making in programming, useful in almost every software development job.
Progress0 / 4 steps