The if statement

The if statement can be perceived as a filter method that is designed to channel the relevant data, and further operate, drive, or act on that information.

As with most programming languages in common practice, there are code blocks that are dependent on certain parameters, variables, and conditions that may only execute when a certain situation is true or false. if statements are used when a decision needs to be made; this works with Boolean logic, which means that the conditions defined for an if can only have two outcomes, true and false:

if (a > b) {
max = a
}

When an if statement is present and the condition is true, the primary code block is executed. If not, the code block is ignored, as we can see in the following example:

fun main(args: Array<String>) {
val langName = "Kotlin"
if ( langName == " Kotlin" ) {
println ( "Hello"+ langName)
}
}

The result would display as Hello Kotlin. When the value of the langName variable is anything other than Kotlin, the code block under the if statement would not be executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.218.221