Skip to content

Instantly share code, notes, and snippets.

@tiagoamaro
Last active March 9, 2022 18:26
Show Gist options
  • Save tiagoamaro/4232f73c8bc55a92cbde9cc1c4bd30c9 to your computer and use it in GitHub Desktop.
Save tiagoamaro/4232f73c8bc55a92cbde9cc1c4bd30c9 to your computer and use it in GitHub Desktop.
Lógica de Programação 2020 - Aula 03
if (condition) {
// This will execute if condition is true
} else if (anotherCondition) {
// This will only be executed if condition is false
// and another condition is true
}
if (condition) {
// This will execute if condition is true
} else {
// Otherwise, this will be executed instead
}
if (booleanCondition && anotherBoolean) {
// If both are true, this will be executed
}
if (condition) {
if (anotherCondition) {
// This will only be executed the first block
}
}
if (lampPlugged) {
// Check if bulb has burned
} else {
// Plug the lamp
}
if (lampPlugged) {
if (burnedBulb) {
// Change the bulb
} else {
// Change the lamp
}
} else {
// Plug the lamp
}
let lampPlugged = true
let burnedBulb = true
if (lampPlugged) {
if (burnedBulb) {
console.log("Need to change de bulb")
} else {
console.log("Change the lamp")
}
} else {
console.log("Plug the lamp")
}
let quantity = 2
let inStock = true
if (inStock) {
quantity = quantity - 1
}
if (quantity === 0) {
inStock = false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment