Enum entries iteration
📖 Scenario: You are creating a simple program to list different types of fruits using an enum in Kotlin. You want to show all the fruit names by going through each enum entry.
🎯 Goal: Build a Kotlin program that defines an enum for fruits and then iterates over all enum entries to print their names.
📋 What You'll Learn
Create an enum class called
Fruit with entries APPLE, BANANA, and CHERRYCreate a variable called
fruitList that holds all entries of the Fruit enumUse a
for loop with variable fruit to iterate over fruitListPrint each
fruit name inside the loop using println(fruit)💡 Why This Matters
🌍 Real World
Enums are used to represent fixed sets of related constants, like days of the week, colors, or fruit types, making code easier to read and maintain.
💼 Career
Understanding enums and how to iterate over them is important for Kotlin developers working on Android apps, backend services, or any Kotlin-based projects.
Progress0 / 4 steps