if Statement

Top  Previous  Next

Executes statements conditionally. It allows more than one flow of control.

Syntax

if (expression)

   statement1

else

   statement2

Description

expression is evaluated and if it is true, statement1 is executed, otherwise, statement2 is executed. If the optional else cause is missing, expression is evaluated and if the resulting value is true, statement is executed. If expression is false, statement is not executed.

Remarks

When working with nested if statements, note that an else clause is part of the nearest if statement.

Examples

var temperature=92;

if (temperature >= 90)

  var alert = 'ON';

Net.write(alert);         // Returns ON