Problem Statement
Explain the different loop constructs in Kotlin including for, while, and repeat.
Explanation
Kotlin's for loop iterates over anything that provides an iterator using in keyword like for open paren item in collection close paren, works with ranges like for open paren i in 1 dot dot 10 close paren, and supports destructuring like for open paren index comma value close paren in list dot withIndex open paren close paren. There's no traditional C-style for loop with initialization, condition, and increment in Kotlin since ranges and functional approaches cover those use cases better.
While and do-while loops work like Java for condition-based iteration like while open paren condition close paren and do open curly body close curly while open paren condition close paren for executing at least once. The repeat function provides a simple way to execute code multiple times like repeat open paren 10 close paren open curly body close curly avoiding the need for a counter variable.
Kotlin's loop constructs are more expressive than Java's, and in many cases functional operations like forEach, map, or filter are preferred over explicit loops for better readability and immutability. Break and continue work in loops with optional labels for nested loop control.
