From 66710393423fb8ce0a170a7b2df6a3815f0124c9 Mon Sep 17 00:00:00 2001 From: Lincoln Ruteski Date: Wed, 27 Mar 2024 16:50:12 -0300 Subject: [PATCH] 14.5 clausula defer --- 14-funcoes_avacadas/14.5-defer/defer.go | 35 +++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 14-funcoes_avacadas/14.5-defer/defer.go diff --git a/14-funcoes_avacadas/14.5-defer/defer.go b/14-funcoes_avacadas/14.5-defer/defer.go new file mode 100644 index 0000000..5390229 --- /dev/null +++ b/14-funcoes_avacadas/14.5-defer/defer.go @@ -0,0 +1,35 @@ +package main + +import "fmt" + +func funcao1() { + fmt.Println("Executando a funcao 1") +} + +func funcao2() { + fmt.Println("Executando a funcao 2") +} + +func alunoEstaAprovado(n1, n2 float32) bool { + defer fmt.Println("Media calculada. Resultado sera retornado") + + fmt.Println("Entrando na funcao para verificar se o aluno esta aprovado") + + media := (n1 + n2) / 2 + + if media >= 6 { + return true + } + + return false +} + +func main() { + // DEFER = ADIAR + // adia a execucao de uma funcao ate o ultimo instante + // defer funcao1() + + // funcao2() + + fmt.Println(alunoEstaAprovado(1, 8)) +}