A loop is used to excute a block of code, i.e, a set of instructions that perform a set of tasks, based on a condition over iterations.
There exists two/three kinds of loops:
- for loops
- while loops
- do-while loops
Eg:
val names = ["Kavya", "Manas", "Likitha"]
for(name in names){
println("Good morning, $name. Have a great day.")
}
- What are loops?
- Syntax to construct a loop
- What are the types of loops and how to choose them
- Syntax of a for loop
- Syntax of a while loop
- Syntax of a do-while loop
- Loops.kt - A simple program in Kotlin to understand loops, their syntax, and power
- ForLoops.kt - A simple program to understand for loops, their syntax, and power.
- Display10Nums.kt - A simple program to display the half of the first 10 whole numbers.
- MultiplicationTable.kt - A simple program to generate the multiplication table for a given number for 10 rows.