View Single Post
  #3  
Old 05-18-2012, 10:01 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Devil_Lord2 View Post
I get up to the question mark which then confuses me...
The question mark is called the ternary operator. It is basically like an if-statement.
Here it is written in English:
RESULT = BOOLEAN ? DO THIS : OTHERWISE DO THIS;

A boolean is simply a statement or value that is either true or false.

Now I'll show you an example of converting an if-else statement into ternary.

PHP Code:
if (this.counter >= 4) {
  
findImg(3).rotation 3;
}else {
  
findImg(3).rotation = -3;

Could essentially be written as the following:
findImg(3).rotation = this.counter >= 4 ? 3 : -3;

The red text is the BOOLEAN. If it's true, it will return/execute whatever is in blue, if it's false, it'll return/execute purple.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote