var Statement

Top  Previous  Next

Declares a variable.

Syntax

var variableName [=value] [..., variableName [=value]]

Arguments

variableNameVariable name.
value     Value assigned to a specific variable.

Description

Declares a variable and optionally initializes it to a value.

Remarks

It is highly recommended to declare variables before function declarations in order to avoid confusions.

Examples

var limit = 100;

var i;

var j;

Net.write("Prime numbers between 1 and " + limit + ": ");

for(i=1; i < 100; i++)

{

   var isPrime = true;

   for(j=2; j < i ; j++)

          {

            if(i % j == 0)

                      {

                        isPrime = false;

                        break;

                      }

           }

            if(isPrime)

            Net.write(i + "  ");                                  // Returns Prime numbers between 1 and 100: 1  2  3  5  7  11  13  17  19  23  29  31  37  41  43  47  53  59  61  67  71  73  79  83  89  97  

}