fun
is 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.
val
keyword is used to store the values that can be set only once. same likeconst
in js. For declaring a changeable variable usevar
1 val age = 15
To 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