What will be the result of the following code execution?

for (
  i1 <- 1 to 5
  if i1 % 2 == 0
  i2 <- 1 to i1
  if i2 > 2
) println(i2)
Explanation
The Scala compiler will not infer semicolons while inside parentheses. That's why it is advantageous to use curly braces, because you can leave off some of the semicolons that are needed when you use parentheses. The following code will be successfully compiled:

for (
  i1 <- 1 to 5
  if i1 % 2 == 0;
  i2 <- 1 to i1
  if i2 > 2
) println(i2)

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Scala
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты