Loop Scala both ways depending on parameters

Viewed 55

I am currently working on some function that takes in two numbers in Scala (I have only worked with Scala once in the past for a few weeks).

I need to iterate a loop between two numbers; a and b.

So if a = 0, b = 10, I want to loop from 0 to 10, if a = 10, b = 0, I wants to loop from 10 to 0.

I want to do this in the most efficient way, how can I do this?

1 Answers
(a to b by (if (a < b) 1 else -1)).foreach { x => ??? }
Related