Bird
0
0

Identify the error in this Kotlin code:

medium📝 Debug Q14 of 15
Kotlin - Loops and Ranges
Identify the error in this Kotlin code:
repeat(3) 
 println("Hi")
AMissing curly braces for the code block
Brepeat cannot be used with println
Crepeat requires a semicolon after the number
DThe number 3 should be a string
Step-by-Step Solution
Solution:
  1. Step 1: Check the syntax of repeat

    The repeat function expects a lambda block enclosed in curly braces after the count.
  2. Step 2: Identify the missing braces

    The code has no braces around println("Hi"), so it is a syntax error.
  3. Final Answer:

    Missing curly braces for the code block -> Option A
  4. Quick Check:

    repeat needs braces { } for code [OK]
Quick Trick: Always use braces { } after repeat(count) [OK]
Common Mistakes:
MISTAKES
  • Omitting braces for single statement
  • Adding semicolon after number
  • Passing number as string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes