0
0
Rustprogramming~15 mins

Boolean type in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean type
๐Ÿ“– Scenario: Imagine you are creating a simple system to check if a store is open or closed based on a boolean value.
๐ŸŽฏ Goal: You will create a boolean variable to represent the store status, then use it to print if the store is open or closed.
๐Ÿ“‹ What You'll Learn
Create a boolean variable called is_open with the value true
Create a boolean variable called is_closed with the value false
Use an if statement to check is_open and print "Store is open" if true
Use an else statement to print "Store is closed" if is_open is false
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Booleans are used everywhere in programming to represent yes/no, on/off, or true/false states, like checking if a user is logged in or if a device is connected.
๐Ÿ’ผ Career
Understanding boolean types and conditional statements is essential for any programming job because they control the flow of decisions in software.
Progress0 / 4 steps
1
Create boolean variables
Create a boolean variable called is_open and set it to true.
Rust
Need a hint?

Use let to create a variable and true for the boolean value.

2
Add second boolean variable
Add a boolean variable called is_closed and set it to false below is_open.
Rust
Need a hint?

Use let and false to create the second boolean variable.

3
Use if statement to check store status
Use an if statement to check if is_open is true. Inside the if, write println!("Store is open");. Add an else block that prints "Store is closed".
Rust
Need a hint?

Use if is_open { ... } else { ... } to decide what to print.

4
Print the store status
Run the program to print the store status based on the is_open boolean variable.
Rust
Need a hint?

Check the console output to see the message.