If Statements

If statements have a simple syntax, which you can see to the right. Start with "if" to begin it, then put your boolean condition (all you need to know for now is that, when this condition is true, the if statment will activate), then put a "then", and end the block with an "end".

If the if statement activates, any code between "then" and "end" will be run, but if it doesn't activate, that code will be skipped.

Below that for our examples, we can see elseif and else statements. Here's how those work: If the first "if" statement fails, then the program will look at the next elseif statement in the block, and check its condition. If that fails, check the next one, and it will repeat this until either A: The elseif has a true condition, in which case the code of the elseif will be run, or B: There are no more elseif statements. If B happens, then the program will check if there's an "else" statement. If there isn't, the block ends and no code is run. If there is, then it runs the code after the else statement until it hits the block's end.

Do note, you are also able to nest if statements inside other if statements when needed, as seen in the final example.

Now, seeing that I've simply written "condition" in each of the statements, I should probably explain how that works. This brings us to the next lesson: Booleans.

if condition then
--code here
end

if condition then
--code here
elseif condition then
--code here
else
--code here
end

if condition then
if condition then
--code here
end
end