You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (a > b) { //if this was a block body, return requred here on the if since if is an expression. return is required for block functions vs expression body
145
+
funifExpressionReturnsAValueWithBlocks(a:Int, b:Int): Int{ //block body
146
+
returnif (a > b) { //if is an expression thus returns the value
147
147
println(" if: a is bigger $a > $b")
148
148
a //return a, 'return' not required since this is an expression body syntax, ie no {} for the block
149
149
} else {
150
150
println(" if: b is bigger $b > $a")
151
151
b //return b
152
152
}
153
+
}
153
154
154
-
//when replaces switch. when can be used as an expression or a statement, excuted sequentially returns a string
155
+
//when replaces switch. when can be used as an expression or a statement, executed sequentially returns a string
155
156
funsimpleWhenAsExpression(a:Int) =
156
157
when(a) {
157
158
in0..5->" range: a in 0..5 range: $a"
@@ -164,7 +165,7 @@ fun simpleWhenAsExpression(a: Int) =
164
165
*/
165
166
funwhenWithSmartCast(a:Any) =
166
167
when(a) {
167
-
isString->println(" smartcast: got a string: $a") //in block we don't have to do typcast, its automagic
168
+
isString->println(" smartcast: got a string: $a") //in block we don't have to do typecast, its automagic
0 commit comments