The if and else statements

The if and else statements have been around for a long time, and almost all languages are dependent on these types of conditional statements for filtering information. When the condition is satisfied, the primary code block will be executed. If the condition fails, the else statement comes into play.

Let's see an example of how this works:

fun main(args: Array<String>) {

val langName = "Java"
if ( langName == "Kotlin" ) {
println ( "I love "+ langName )
}
else {
println ("The name of the language is "+ langName )
}
}

If the langName variable is assigned a "Kotlin" string, then the first code block of the if statement will be executed. If not, the  else statement will 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.138.123.106