if y elseif en Lua
Los bloques cierran con end; and/or hacen de selector de valores.
-- Blocks close with end; elseif chains without extra nesting.
local torchlight = 3
if torchlight > 6 then
print("The hall is bright")
elseif torchlight > 2 then
print("Shadows crowd the corners")
else
print("Total darkness")
end
-- and/or short-circuit; the a and b or c idiom picks a value.
local hp = 4
local status = hp > 10 and "steady" or "limping"
print("Status: " .. status)
if hp < 5 then print("Find a campfire soon") end
Cómo funciona
if/elseif/elseencadenan sin anidar de más.and/orcortocircuitan; solo nil y false son falsos.cond and a or bes el ternario de Lua — seguro mientras a sea veraz.
Palabras clave y builtins usados aquí
elseelseifendiflocalprintthen
El intento, en números
- Líneas
- 16
- Caracteres a escribir
- 433
- Tokens
- 74
- Ritmo de tres estrellas
- 70 tpm
Al ritmo de tres estrellas de 70 tokens por minuto, este intento toma unos 63 segundos.
Paso 1 de 3 en Control de flujo; paso 4 de 27 en Fundamentos del lenguaje.