FANDOM


A statement uses logic to do things. There are a bunch of different kinds, but for this section we will be talking about the "if" statement. The if statement looks like this.

if( condition )
{


}

What it basically does is check if the "condition" inside the parenthesese is true. You could use the if statement to check if a variable is set to true, false, 0, 1 hi, ect. If whatever you input inside the parenthesis is true, it will execute the code within the curly braces. Here are a couple of examples with what they represent.


myFunction( word )
{
    if( word == "hey" || word == "hi" )
    {
        self IPrintLn( word );
    }
}
  • If the variable "word" is euqal to "hey" or "word" is equal to "hi", print the word on the screen.


myFunction( word )
{
    if( word == "hey" && isAlive( self ) )
    {
        self IPrintLn( word );
    }
}
  • If the variable "word" is equal to "hey" and self is alive, print the word on the screen.


myFunction( digit )
{
    if( digit > 0 )
    {
        self IPrintLn( "Digit is bigger then 0!" );
    }
}
  • If the variable "digit" is greater then 0, print "Digit is bigger then 0!!!" on the screen.



From looking at those example, you might be thinking "what the heck are those things between the 2 variables". Well, those things are called comparison operators. They compare the two variables and if they return a true value to the game, it will execute the code inside the curly braces. Here is what each comparison operator looks like and what they do.

==    // is equal to
!=    // is not equal to
>     // is grater than
<     // is less than
>=    // is equal to or greater than
<=    // is equal to or less than



Now you might be thinking, "but you used '||' and '&&'!!!"; well those are called logical operators. Here's what they look like and what they do.

!     // not
&&    // and
||    // or



If you want an if statement to check if two tests are true then you would do...

if( variable > 5 && variable < 10 )
{
    // execute this...
}
  • The above would check if "variable" is bigger then 5 and(&&) "variable" is smaller then 10


If you want an if statement to check if one test or another is true, you would do..

if( variable == 0 || variable == 1 )
{
    // execute this...
}
  • The above would check if "variable" equals 0 or(||) if variable equals 1


The final operator is basically the same as not equal to.

if( !( variable > 5 ) )
{
    // execute this...
}
  • The above is basically checking if "variable" is not greater then 5


Now that we've covered the basic "if" statement, it's time to move onto the "if-else" statement, which will be covered on a new page.