Switch with compound cases
📖 Scenario: Imagine you are building a simple app that categorizes fruits based on their names. You want to group some fruits together because they share similar characteristics.
🎯 Goal: You will create a program that uses a switch statement with compound cases to print the category of a fruit.
📋 What You'll Learn
Create a variable called
fruit with the value "apple".Create a variable called
citrusFruits that holds the fruits "orange" and "lemon".Use a
switch statement on the fruit variable with compound cases to check if the fruit is an apple or banana, or if it is a citrus fruit.Print the category of the fruit using
print.💡 Why This Matters
🌍 Real World
Grouping items by categories is common in apps that organize data, like grocery lists or inventory systems.
💼 Career
Understanding switch statements with compound cases helps in writing clear and efficient code for decision-making in many software projects.
Progress0 / 4 steps