Skip to content

Instantly share code, notes, and snippets.

@oluies
Created May 28, 2011 17:34
Show Gist options
  • Save oluies/997054 to your computer and use it in GitHub Desktop.
Save oluies/997054 to your computer and use it in GitHub Desktop.
print mult table 1 to 12 as a square
// print mult table 1 to 12 as a square
for( a <- (1 to 12); b <- (1 to 12)){
print("%4s".format(a*b))
if (b == 12) println("")
}
println("")
// is sugar for
(1 to 12).foreach( a => (1 to 12).foreach( b => {
print("%4s".format(a*b))
if(b == 12) println("")
}))
println("")
// this should be as fast as a java equivelent
var a = 1; var b = 1;
while(a <= 12){
b = 1
while(b <= 12){
print("%4s".format(a*b))
if(b == 12) println("")
b += 1
}
a += 1
}
println("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment