If statements

From CodeStuff
Jump to: navigation, search

You can use if statements to optionally run a piece of code.

The if statement takes the form

if (condition) {
 actions;
}


You can optionally provide code to be run when the condition is not true with else.

if (condition) {
  things to do when the condition is true
} else {
  otherwise do the things here
}


In the example Below, the circle is filled when the mouse pointer is inside it.