In Kotlin, conditional statements are essential for controlling the flow of statements in the program. If Else statement executes a particular statement based on conditions. This tutorial will teach us how to use If-Else Conditional Statements in Kotlin with easy examples.
If-Else Conditional Statement in Kotlin: A Beginner’s Guide with Examples
What is If-Else?
In Kotlin If-Else allows us to execute a code of block when a certain condition is true. If the condition is false then it will execute the Else part of the statements.
Syntax:
Example 1:
In this example, we will check whether a Number is positive or not.
In the same above-mentioned example, we will pass the value in minus then it will execute the else part.
Example 2:
In this example, we will use If-Else with multiple conditions.
With If-Else we can control the flow of our program and change the direction of our program on a certain condition. Keep practicing the code and you will get used to it. If anything is required from my side please feel free to comment, Happy coding.