Last active
November 19, 2019 16:27
-
-
Save dgadiraju/4eaeaff6296752f0132086c646ca7d55 to your computer and use it in GitHub Desktop.
This file contains 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
//Expression | |
println("********") | |
println("Expression") | |
val c = { | |
val i = (math.random * 100).toInt | |
val j = (math.random * 100).toInt | |
i - j | |
} | |
println(c) | |
//Nested block | |
val a = { | |
val x = 0 | |
val y = 1 | |
val b = { | |
val y = 2 | |
println("value of x inside nested block is " + x) | |
println("value of y inside nested block is " + y) | |
} | |
println("value of x inside main block is " + x) | |
println("value of y inside main block is " + y) | |
} | |
println("********") | |
println("Another Expression") | |
val sqr = { | |
val a = 1 | |
val b:Long = 23L | |
val hi = "hi" | |
true | |
} | |
println(sqr) | |
// Start writing your ScalaFiddle code here | |
//if-else-if-else | |
val i = 10 | |
val j = 20 | |
println("********") | |
println("if else") | |
if(i > j) { | |
println(i) | |
} else if(i == j) { | |
println("Equal") | |
} else { | |
println(j) | |
} | |
//ternary operator, it uses if else | |
println("********") | |
println("Ternary") | |
if(i > j) println(i) else println(j) | |
//while loop | |
println("********") | |
println("While loop") | |
var ctr = 0 | |
while(ctr <= i) { | |
println(ctr) | |
ctr += 1 | |
} | |
//for loop | |
ctr = 5 | |
println("********") | |
println("For loop") | |
for(a <- ctr to j) { | |
println(a) | |
} | |
println("********") | |
println("For loop increment by constant") | |
val constant = 2 | |
for(a <- ctr to j by constant) { | |
println(a) | |
} | |
println("********") | |
println("For loop decrement by constant") | |
for(a <- j to ctr by -constant) { | |
println(a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment