Difference between revisions of "If statements"
From CodeStuff
(Created page with "You can use if statements to optionally run a piece of code. The if statement takes the form if (condition) { actions; } <edcode> if (true) { print("this text will al...") |
|||
| Line 9: | Line 9: | ||
<edcode> | <edcode> | ||
if (true) { | if (true) { | ||
| − | print("this text will | + | print("this text will always appear"); |
} | } | ||
| Line 17: | Line 17: | ||
if (5<10) { | if (5<10) { | ||
| − | print("five is less than ten") | + | print("five is less than ten"); |
} | } | ||
if (20<10) { | if (20<10) { | ||
| − | print("twenty is less than ten") | + | print("twenty is less than ten"); |
} | } | ||
</edcode> | </edcode> | ||
| Line 43: | Line 43: | ||
} | } | ||
| − | run(update) | + | run(update); |
</edcode> | </edcode> | ||
| Line 65: | Line 65: | ||
} | } | ||
| − | run(update) | + | run(update); |
</edcode> | </edcode> | ||
Latest revision as of 05:52, 16 April 2015
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.