Key Concepts

Review core concepts you need to learn to master this subject

Else Statements

if isSunny then print("Go outside!") else --This statement executes when every expression in --a control statment is false. print("Stay indoors.") end

Lua else statements will execute a code block if every expression in the if-based control structure evaluates to false. If an else is included in a control structure, the else must go at the end.

Conditionals & Logic
Lesson 1 of 1
  1. 1
    Every day, we need to make decisions in our lives. We make these decisions based on the current conditions. If we are hungry, then we will make food. If we have lettuce and dressing, then we will m…
  2. 2
    The foundation of every control structure starts with an if statement. if statements require two parts: 1. a boolean expression — a variable or some code that evaluates to a true or false value…
  3. 3
    So far, we have used the most basic boolean expressions for our if statements. Now it is time to do something a little more interesting. Often we need to compare two values to make a decision. For…
  4. 4
    Next, let’s talk about a common scenario: We want something to happen if our condition is true OR we want something else to happen if our condition is false. We could write this: isHungry = true i…
  5. 5
    Imagine we are in the kitchen making a delicious sandwich, but when we check the fridge, we notice that we don’t have ham. We don’t just throw out the sandwich because we don’t have ham. We first w…
  6. 6
    At every step of this lesson, we have been learning more tools that help us take complicated control structures and define them for a computer. Let’s take it another step further! What happens whe…
  7. 7
    Now that we have created more complicated boolean expressions, how does the computer know which operators to execute first? Lua, like most programming languages, has an order of operations. G…
  8. 8
    As we have seen from the last exercise, we need more tools to help us in our journey of making control statements. We are in luck — there is a tool that controls the order of operations! It is the …
  9. 9
    Amazing job! We learned a lot in this lesson so let’s review some of the topics. score = 60 hasFreePass = false if score == 100 or hasFreePass then print(“You got an A+”) elseif score = 70 th…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo