Skip to content

Commit

Permalink
14.5 clausula defer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteski committed Mar 27, 2024
1 parent 14377af commit 6671039
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions 14-funcoes_avacadas/14.5-defer/defer.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 6671039

Please sign in to comment.