Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA SCRIPT

If-Then Branching

 

Branching that involves "if-then" allows your program to behave very differently depending on what a user inputs. For example, you could write a script that would act one way toward you and a different way toward everyone else. Here's the basic form of an if-then statement:

 

if (some condition is true)

{ 

    do something;

    do something;

    do something;	

}

The important parts of this structure are:

 

  • It starts with the word "if" (if must be lowercase).
  • There is a condition in parentheses that is either true or false.
  • There is a set of statements that should be executed if the condition is true. These statements go between curly brackets.

Remember, spacing is only there to make the script more legible. You can put the entire if-then statement on one line if you want, but that would be hard to read.

<Previous                                                                                                      Next>