Created
December 23, 2021 11:19
-
-
Save arsalankhan994/db56217961cb9619342ee527ef99d17c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
/* | |
1. for loop using "in" | |
*/ | |
for(i in 0..5) { | |
println("for loop using in") | |
} | |
/* | |
2. for loop using "until" | |
*/ | |
for (i in 0 until 5) { | |
println("for loop using until") | |
} | |
/* | |
3. foreach on List | |
*/ | |
val names: List<String> = listOf("Erselan", "Khan") | |
names.forEach { | |
println(it) | |
} | |
/* | |
4. foreach on List 2nd example | |
*/ | |
for (name in names) { | |
println(name) | |
} | |
/* | |
5. while loop | |
*/ | |
var i = 5 | |
while (i > 0) { | |
println("while loop") | |
i-- | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment