Created
December 19, 2018 01:03
-
-
Save parzibyte/3d9f5fe50f7f4bd40ee1c734bed6e497 to your computer and use it in GitHub Desktop.
Defer en Go | Otro ejemplo created by parzibyte - https://repl.it/@parzibyte/Defer-en-Go-or-Otro-ejemplo
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
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Escribe tu edad:") | |
var edad int | |
fmt.Scanln(&edad) | |
// Al final, siempre mostrar este mensaje | |
defer fmt.Println("Gracias. Vuelva pronto") | |
if edad < 18{ | |
fmt.Println("No puedes acceder al mensaje secreto") | |
return//Termina la función | |
} | |
fmt.Println("Hola, soy un mensaje que se muestra si tienes más de 18 años") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment