Kotlin break Expression In this tutorial, you will learn to use break to terminate a loop. Also, you will also learn about break labels. Suppose you are working with loops. It is sometimes desirable to terminate the loop immediately without checking the test expression. In such case, break is used. It terminates the nearest enclosing loop …
Day: May 3, 2021
Kotlin for Loop The for loop in Kotlin iterates through anything that provides an iterator. In this article, you learn to create for loop (with the help of examples). There is no traditional for loop in Kotlin unlike Java and other languages. In Kotlin, for loop is used to iterate through ranges, arrays, maps and so on (anything that provides …
Kotlin while and do…while Loop Loop is used in programming to repeat a specific block of code. In this article, you will learn to create while and do…while loops in Kotlin programming. Loop is used in programming to repeat a specific block of code until certain condition is met (test expression is false). Loops are what …
Kotlin when Expression In this article, you will learn about when construct in Kotlin with the help of various examples. Kotlin when Construct Example: Simple when Expression fun main(args: Array<String>) { val a = 12 val b = 5 println(“Enter operator either +, -, * or /”) val operator = readLine() val result = when …
Kotlin if Expression In this article, you will learn to use if expression in Kotlin with the help of examples. Traditional Usage of if…else The syntax of if…else is: if (testExpression) { // codes to run if testExpression is true } else { // codes to run if testExpression is false } if executes a certain …
Kotlin Basic Input/Output In this article, you will learn to display output to the screen, and take input from the user in Kotlin. Koltin Output You can use println() and print() functions to send output to the standard output (screen). Let’s take an example: fun main(args : Array<String>) { println(“Kotlin is interesting.”) } When you run the program, the …
Kotlin Comments In this article, you will learn about Kotlin comments, and why and how to use them. In programming, comments are portion of the program intended for you and your fellow programmers to understand the code. They are completely ignored by the Kotlin compiler (Kompiler). Similar like Java, there are two types of comments in …
Kotlin Expression, Statements and Blocks In this article, you will learn about Kotlin expressions, Kotlin statements, difference between expression and statement, and Kotlin blocks. Kotlin Expressions Expressions consist of variables, operators etc that evaluates to a single value. Let’s take an example, val score: Int score = 90 + 25 Here, 90 + 25 is an expression that returns Int value. In …
Kotlin Type Conversion In this article, you will learn about type conversion; how to convert a variable of one type to another with the help of example. In Kotlin, a numeric value of one type is not automatically converted to another type even when the other type is larger. This is different from how Java handles …
Kotlin Operators Kotlin has a set of operators to perform arithmetic, assignment, comparison operators and more. You will learn to use these operators in this article. Operators are special symbols (characters) that carry out operations on operands (variables and values). For example, + is an operator that performs addition. 1. Arithmetic Operators Here’s a list of arithmetic …