Last active
March 25, 2020 21:49
-
-
Save nunomazer/edd830811407b5588bdd524110c472a6 to your computer and use it in GitHub Desktop.
Condicionais em Dart
This file contains hidden or 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(){ | |
double media = 4.9; | |
// IF (condiçao verdadeira) / ELSE | |
if (media < 6.0){ | |
print("Reprovado!"); | |
} else { | |
print("Aprovado!"); | |
} | |
/* Podemos também utiliar IF TERNÁRIO | |
* CONDIÇÃO ? RETORNO VERDADEIRO : RETORNO FALSO | |
*/ | |
media = 8; | |
print(media < 6.0 ? "Reprovado!" : "Aprovado"); | |
/* Toda variável declarada e que não recebe valor, automáticamente é nula | |
* VARIAVEL ?? RETORNO CASO SEJA NULO | |
*/ | |
String linguagem; | |
print(linguagem ?? "Variável com valor nulo"); | |
linguagem = "Dart"; | |
print(linguagem ?? "Não vai retornar esta string"); | |
/* SWITCH / CASE / DEFAULT | |
* Utilizado geralmente quando temos constantes | |
* Cada cláusula de case não vazio termina com uma instrução break, como regra. | |
*/ | |
switch(linguagem){ | |
case "Dart": | |
print("É Dart!"); | |
break; | |
case "Java": | |
print("É Java!"); | |
break; | |
case "C#": | |
print("É C#!"); | |
break; | |
default: | |
print("Qualquer outra linguagem"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment