Created
November 12, 2011 02:49
-
-
Save tiagodavi/1359955 to your computer and use it in GitHub Desktop.
Exemplo de for super legal utilizando Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Exemplo de for super legal utilizando Scala | |
object Laco{ | |
//main (um pouquinho diferente do java) | |
def main(args: Array[String]){ | |
for{ | |
/* | |
Para cada 5 incrementos em i vai haver 1 incremento em j | |
Quando i chegar a 5 vai resetar seu contador para 1 e j vai incrementar para 2 | |
E assim sucessivamente... ate j chegar a 5 | |
*/ | |
i <- 1 to 5 | |
j <- 1 to 5 | |
} | |
//Multiplica as iteracoes (perceba que esta fora do escopo do for) | |
println(i * j) | |
/* | |
Saida | |
1 | |
2 | |
3 | |
4 | |
5 | |
2 | |
4 | |
6 | |
8 | |
10 | |
3 | |
6 | |
9 | |
12 | |
15 | |
4 | |
8 | |
12 | |
16 | |
20 | |
5 | |
10 | |
15 | |
20 | |
25 | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment