Student of Scala may have some doubts when learning for-enumerators, and may not understand the execution order of if enumerator. They may think that if is similar to match grammer, they think if i + j == v will execute before j <-....
look at this example
val a = Array(1, 2, 3)
val value = for
i <- 0 to 5;
j = a(i) if i % 2 == 0
yield (j)
Actually, it should be
val a = Array(1, 2, 3)
val value = for
i <- 0 to 5 if i % 2 == 0
j = a(i)
yield (j)
sorry,I check this PR again,My friend doesn't read the documentation very well.
This section has explained very clearly how if works in for-comprehensions.
Student of Scala may have some doubts when learning for-enumerators, and may not understand the execution order of
if enumerator
. They may think that if is similar to match grammer, they thinkif i + j == v
will execute beforej <-...
. look at this exampleActually, it should be