1

I have this array:

  var walls: Array[LineSprite] = new Array[LineSprite](20)

And I want to make is so that for all the items in the array between 11 and less than or equal to 19, the start is set to -2,-2 and the end is set to -3,-3.

To do that for one of the items it would look like this:

walls(0).setStart(-2,-2)
walls(0).setEnd(-3,-3)

How would I do what I want using foreach?

Thanks

1 Answer 1

6

Do you mean this?

for (i <- 11 to 19) {
  walls(i).setStart(-2,-2)
  walls(i).setEnd(-3,-3)
}

This translates to:

(11 to 19) foreach { i =>
  walls(i).setStart(-2,-2)
  walls(i).setEnd(-3,-3)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.