Using Range Operator (..) and in Operator in Kotlin
📖 Scenario: You are organizing a small event and want to check if guests' ages fall within a certain age range for eligibility.
🎯 Goal: Build a Kotlin program that uses the range operator .. to create an age range and the in operator to check if a guest's age is within that range.
📋 What You'll Learn
Create an integer variable called
guestAge with the value 25Create a range called
eligibleAgeRange from 18 to 30 using the .. operatorUse an
if statement with the in operator to check if guestAge is in eligibleAgeRangePrint
"Guest is eligible" if the age is in range, otherwise print "Guest is not eligible"💡 Why This Matters
🌍 Real World
Checking if a person's age or a number falls within a valid range is common in forms, games, and eligibility checks.
💼 Career
Understanding ranges and membership tests is useful for data validation, filtering, and controlling program logic in many software development roles.
Progress0 / 4 steps