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
if
block will run. - If the condition is false, then the code in our
else
block will run instead (if we even have anelse
block… because that’s optional!)