Last active
April 20, 2021 09:00
-
-
Save davidmigloz/ec54600bb6f4c47960ca285b1da49d9c to your computer and use it in GitHub Desktop.
Dart vs Kotlin: loops
This file contains 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
void main() { | |
for (var i = 5; i >= 0; i = i - 2) { | |
print(i); // 5 3 1 | |
} | |
for (var num in [1, 4, 5, 2]) { | |
print(num); // 1 4 5 2 | |
} | |
final set = {"A", "B", "C"}; | |
set.forEach((letter) { | |
print(letter); // A B C | |
}); | |
outer: // Label | |
for (var i = 0; i < 100; i++) { | |
for (var j = 0; j < 100; j++) { | |
if (i > 10) break outer; | |
} | |
} | |
} |
This file contains 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() { | |
for (i in 5 downTo 0 step 2) { | |
println(i) // 5 3 1 | |
} | |
for (num in listOf(1, 4, 5, 2)) { | |
println(num) // 1 4 5 2 | |
} | |
val set = setOf("A", "B", "C") | |
set.forEach { letter -> | |
println(letter) // A B C | |
} | |
outer@ for (i in 0..100) { | |
for (j in 0..100) { | |
if (i > 10) break@outer | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment