In Kotlin, if is an expression, not just a statement — it can return a value:
val max = if (a > b) a else b
when — Kotlin’s more powerful switch
fun describe(score: Int): String = when {
score >= 90 -> "Excellent"
score >= 70 -> "Good"
score >= 50 -> "Pass"
else -> "Needs Improvement"
}
Loops
for (i in 1..5) {
println(i)
}
val fruits = listOf("Apple", "Banana", "Cherry")
for (fruit in fruits) {
println(fruit)
}
var count = 0
while (count < 3) {
println("Count: $count")
count++
}
1..5 is a range — inclusive of both ends. Use 1 until 5 if you want to exclude the last value.
- Image
- SKU
- Rating
- Price
- Stock
- Availability
- Add to cart
- Description
- Content
- Weight
- Dimensions
- Additional information