-
-
Save parzibyte/fd4fd99532ddd3fb65138116989779f0 to your computer and use it in GitHub Desktop.
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(argumentos: Array<String>) { | |
/** | |
* Ciclos en Kotlin: | |
* while | |
* do while | |
* for | |
* | |
* @author parzibyte | |
* @link https://parzibyte.me/blog | |
* */ | |
// Ciclo del 0 al 9 | |
// usando un rango | |
// https://parzibyte.me/blog/2019/07/05/rangos-kotlin/ | |
val rangoDeNumeros = 0..9 | |
for (numero in rangoDeNumeros) { | |
println(numero) | |
} | |
// Recorrer un arreglo | |
// Más sobre arreglos: https://parzibyte.me/blog/2019/07/02/arreglos-kotlin/ | |
val nombres = arrayOf("John Galt", "Dagny Taggart", "Hank Rearden") | |
for (nombre in nombres) { | |
println(nombre) | |
} | |
// Ciclo con while y contadores | |
var contador = 5 | |
while (contador > 0) { | |
println("Cuenta regresiva: $contador") | |
contador-- | |
} | |
do { | |
println("Me ejecuto una vez") | |
} while (false) | |
// También existe el do while | |
var otroContador = 0 | |
do { | |
println("Contador: $otroContador") | |
otroContador++ | |
} while (otroContador < 5) | |
// Recorrer un arreglo: | |
var indice = 0 | |
while (indice < nombres.size) { | |
println("Un nombre: ${nombres[indice]}") | |
indice++ | |
} | |
// Ciclo con flotantes | |
var contadorFlotantes = 0.1 | |
while (contadorFlotantes < 1.0) { | |
println("Contando del 0.1 al 1.0: $contadorFlotantes") | |
contadorFlotantes += 0.1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment