Skip to content

Bug in collections-loops implementation #1

@barkantoprak

Description

@barkantoprak

Hi, there is an error in collections-loops implementation.

At while loop, the incrementation of variable "i" must be outside of while loop or should be implemented differently.

Because, if the condition in while loop is not met, the "i" is not incremented and causes it to work incorrectly.

I think this is the correct solution:

var i = 0

while (i < randoms.size) {
  if (randoms[i] <= 10) { //it is mentioned less than or equal to 10 in challenge
    println(randoms[i])
  }
  i++
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions