Control Flow
Learn control flow in Kotlin using the if and when expressions.
We'll cover the following...
We can say that the control flow is the bread and butter of writing programs. We’ll start with two conditional expressions, if
and when
.
The if
expression
In Java, if
is a statement. Statements do not return any value. Let’s look at the following function, which returns one of two possible values:
public String getUnixSocketPolling(boolean isBsd) {if (isBsd) {return "kqueue";}else {return "epoll";}}
if statement in Java
While this example is easy to follow, ...