Coding Friction

kotlin

Kotlin Lambda Function

Lambda is a function which has no name. It is a concise way to define a block of code that can be passed around as an argument to higher-order functions or stored in a variable for later use. Lambda functions are useful in various contexts, such as higher-order functions, collections operations (like map, filter, and …

Kotlin Lambda Function Read More »

Kotlin Recursion function

A recursive function is a function that calls itself in its own definition.  Let’s look at an example of a simple recursive function to calculate the factorial of a number: When you call factorial(5), the recursive calls break down as follows: The function repeatedly calls itself with smaller values until it reaches the base case, …

Kotlin Recursion function Read More »

Kotlin function

Functions are blocks of code that perform a specific task and can be called multiple times within a program. By using functions, we can avoid repeating the same code, which makes our program cleaner and more organized. functions are declared using fun keyword in kotlin Let’s create a simple example that calculates the area of …

Kotlin function Read More »

Kotlin Array

Array is a collection of similar data types such as an Int, String etc. It is used to organize data so sorted and searched can be easily done. Arrays are mutable and fixed size, they are stored in contiguous memory locations. Create an Array : In Kotlin there are two ways to create an array 1. …

Kotlin Array Read More »

Kotlin Return and jump

These are the jump expression are used to control the flow of program execution. return : By default returns from the nearest enclosing function or anonymous function continue : Proceeds to the next step of the nearest enclosing loop break : It is used to  terminates the nearest enclosing loop. it is used to bring …

Kotlin Return and jump Read More »

Kotlin do-while loop

do-while loop first executes the code of do block then it checks the┬ácondition. do-while loop executes at least once even the condition of while is false. Syntax Example Let’s see an example where a block of code executes only once and the condition in while is false.

Kotlin while Loop

It is used to iterate a part of code several times. It executes until the condition is true. Syntax let’s take an example: Iterate through Array using while loop

Kotlin for Loop

It is used to iterate a part of code several times. it iterate through array, collection(like list, map), ranges, String. If body of for loop have only single statement we don’t need to use  curly braces {}. Syntax iterate through range using for loop : in is the operator to check the value in the …

Kotlin for Loop Read More »

Kotlin when Expression

when is the replacement of the switch operator of java. Block of code will executed when some condition is satisfied, also when expression can returns value using braces we can use multiple statements. it can also be used as a statement without any other branch. Let’s take an example. Example 1: Example 2: Combine multiple …

Kotlin when Expression Read More »

Kotlin Control Flow

Kotlin Control Flow Statements It is used to control the flow of program structure, following types of expression in kotlin. if Expression : if the condition of if block is true than if block executes. Syntax: if-else Expression : if condition of If block is true than if block will be executed otherwise else block …

Kotlin Control Flow Read More »