January 2018
Intermediate to advanced
434 pages
14h 1m
English
We have already seen how we can use string templates with expressions in print statements. Remember how we were able to access a variable using the $ symbol before the name of a variable:
println("$x is a magic number”)
We can also put a piece of code in a string, which is then evaluated and whose results are concatenated into the string. In this case, $ is followed by {}, inside which we put our code:
println("lies between 1 to 10, value: ${if(x.value < x.max) x.value else x.max}")
Read now
Unlock full access