Want to make decisions in your code? Want to make your code respond to different situations? You might need if statements.
Try this code:
if(mouseX < 200)
{
background(0) // if true
}
else
{
background(100) // if false
}What happens? Why?
An if statement reacts to true or false.
- If the condition is true, then the code in our
ifblock will run. - If the condition is false, then the code in our
elseblock will run instead (if we even have anelseblock… because that’s optional!)