Using Director > Writing Scripts with Lingo > Controlling flow in scripts > Using if statements |  |

Using if statements

Statements that check whether a condition is true or false begin with the Lingo term `if`. If the condition exists, Lingo executes the statement that follows `then`. If the condition doesn't exist, Lingo skips to the next statement in the handler.

To optimize your script's performance, test for the most likely conditions first.

The following statements test several conditions. The term `else if` specifies alternative tests to perform if previous conditions are false:

    if the mouseMember = memberNum("map 1") then
    	go to "Cairo"
    else if the mouseMember = member ("map 2") then
    	go to "Nairobi"
    else
    	alert "You're lost."
    end if

When writing `ifthen` structures, you can place the statement following `then` in the same line as `then`, or you can place it on its own line by inserting a carriage return after `then`. If you insert a carriage return, you must also include an `end if` statement at the end of the `ifthen` structure.

For example, the following statements are equivalent:

    if the mouseMember = member("map 1") then go to "Cairo"
    if the mouseMember = member("map 1") then
    	go to "Cairo"
    end if

For more information, see `if` and `case` in.