Skip to main content

Posts

Showing posts from February 27, 2023

Kotlin If Expression

Kotlin if Expression In Kotlin, if is an expression is which returns a value. It is used for control the flow of program structure. There is various type of if expression in Kotlin. if-else expression if-else if-else ladder expression nested if expression Traditional if Statement Syntax of traditional if statement if(condation){      //code statement } Syntax of traditional if else statement if(condation){      //code statement } else{      //code statement } Kotlin if-else Expression As if is an expression it is not used as standalone, it is used with if-else expression and the result of an if-else expression is assign into a variable.   Syntax of if-else expression val returnValue = if (condation) {      //code statement } else {      // code statement }      println(returnValue) Kotlin if-else Expression Example Let's see an example of if-else expression. fun main(args: Array ) {      val num1 = 10

Kotlin Operator

Kotlin Operator Operators are special characters which perform operation on operands (values or variable).There are various kind of operators available in Kotlin. Arithmetic operator Relation operator Assignment operator Unary operator Bitwise operation Logical operator Arithmetic Operator Arithmetic operators are used to perform basic mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/) etc.   + Addition a+b a.plus(b) - Subtraction a-b a.minus(b) * Multiply a*b a.times(b) / Division a/b a.div(b) % Modulus a%b a.rem(b) Example of Arithmetic Operator fun main(args : Array ) {      var a=10;      var b=5;      println(a+b);      println(a-b);      println(a*b);      println(a/b);     println(a%b); } Relation Operator Relation operator shows the relation and compares between operands. Following are the different relational operators: > greater than a>b a.compateTo(b)>0 < Less than a >= greate