funis a leyword used to define a function.1 fun main() { 2 println("Happy Birthday!") 3 println("Jhansi") 4 println("You are 25!") 5 }print()vsprintln()print()just prints the text without using a line break at end of string.
valkeyword is used to store the values that can be set only once. same likeconstin js. For declaring a changeable variable usevar1 val age = 15To use a variable inside a print statement surround it with
{}1 println("Age of a Surya is ${age}")Use a
repeat()function to repeat an instruction for ‘n’ number of times. This is one of a kind of loops1 printSigns(){ 2 //prints + sign for 50 times 3 repeat(50){ 4 print("+") 5 } 6 }- To create a Nested loop use
repeat()inside arepeat()1//print the layers of the cake age times 2fun printCakeBottom(age: Int, layers: Int) { 3 repeat(layers) { 4 repeat(age + 2) { 5 print("@") 6 } 7 println() 8 } 9}
- To create a Nested loop use