Statements

Old Content - visit altium.com/documentation

Parent page: JScript

JScript Statements

This section of the JScript reference includes JScript:
Conditional Statements
Expressions and Operators

Conditional Statements

The main conditional statements supported by JScript are;

  • if (expression) else
  • else if
  • switch
  • while loop
  • do while loop
  • for loop
  • for in

Care needs to be taken to code scripts that avoid infinite loops — that is, ensuring that the conditions will eventually be met.

The if.. else statement

The syntax is:

if Condition {
}
else if ANotherCondition {
}
else{
}

The switch statement

The switch statement is like a multi-way branch. The basic syntax is:

switch (n) {
case 1: n == 1
  //execute code.
  break
case 2: n==2
  //execute code.
break;
default: // if all else fails...
  //execute code.
break;
}

The while statement

The while statement is a basic statement that allows repetitive actions until a condition is met. It is possible that the statements inside the while body never get executed if the condition is not met once.

while (expression) {
  //statement...
}

The do...while statement

The do...while statement is a variation on the while statement, where the loop expression is tested at the bottom of the loop rather than at the top. This means the body of the loop is always executed at least once. The general syntax is:

do
  // statements
while (expression);

The for statement

The for statement provides a common loop statement with a counter variable of some kind. The syntax is:

for (initialize ; test ; increment)
  //statement

Example

for (count = 0; count < 10; count ++)
  showmessage(inttostr(count));

The for...in statement

The for...in statement provides a way to loop through the properties of an object, or all the elements of an array. The for...in loop does not specify the order in which the properties of an object are assigned to the variable.

for (variable in object)
  //statement.

Expressions and Operators

An expression is a valid combination of constants, variables, literal values, operators and function results. Expressions are used to determine the value to assign to a variable, to compute the parameter of a function or to test for a condition. Expressions can include function calls.

JScript has a number of logical, arithmetic, Boolean and relational operators. These operators are grouped by the order of precedence, which is different to the precedence orders used by Basic, C etc. For example, the AND and OR operators have precedence compared to the relational one.

Arithmetic Operators

+

Addition

-

Subtraction

*

Multiplication

/

Division

%

Modulo

Decrement

++

Increment

-

Unary negation

Logical Operators

!

Logical Not

<

Less than

>

Greater than

<=

Less than or equal to

=>

Greater than or equal to

==

equality

!=

inequality

&&

Logical and

||

Logical or

?:

conditional ternary

,

comma

===

strict equality

!==

strict inequality

Bitwise Operators

~

Bitwise Not

<<

Bitwise Left Shift

>>

Bitwise Right Shift

>>>

Bitwise Unsigned right shift

&

Bitwise And

^

Bitwise Bitwise XOR

|

Bitwise OR

Operator Precedence

Operator

Description

. [] ()

Field access, array indexing, function calls, and expression grouping

++ -- - ~ ! delete new typeof void

Unary operators, return data type, object creation, undefined values

* / %

Multiplication, division, modulo division

+ - +

Addition, subtraction, string concatenation

<< >> >>>

Bit shifting

< <= > >= instanceof

Less than, less than or equal, greater than, greater than or equal, instanceof

== != === !==

Equality, inequality, strict equality, and strict inequality

&

Bitwise AND

^

Bitwise XOR

|

Bitwise OR

&&

Logical AND

||

Logical OR

?:

Conditional

= OP=

Assignment, assignment with operation

,

Multiple evaluation

You are reporting an issue with the following selected text and/or image within the active document:
ALTIUM DESIGNER FREE TRIAL
Altium Designer Free Trial
Let’s get started. First off, are you or your organization already using Altium Designer?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

In that case, why do you need an evaluation license?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Got it. You actually don’t need an evaluation license for that.

Click the button below to download the latest Altium Designer installer.

Download Altium Designer Installer

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Please fill out the form below to get a quote for a new seat of Altium Designer.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

If you are on Altium Subscription, you don’t need an evaluation license.

If you are not an active Altium Subscription member, please fill out the form below to get your free trial.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Why are you looking to evaluate Altium Designer?

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

You came to the right place! Please fill out the form below to get your free trial started.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Sounds exciting! Did you know we offer special discounted student licenses? For more information, click here.

In the meantime, feel free to request a free trial by filling out the form below.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

Got it. You can download a free Altium Designer Viewer license which is valid for a 6 months.

Please fill out the form below to request one.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.

That’s great! Making things is awesome. We have the perfect program for you.

Upverter is a free community-driven platform designed specifically to meet the needs of makers like you.

Click here to give it a try!

If would like to speak with a representative, please contact your local Altium office.
Copyright © 2019 Altium Limited

Got it. You can download a free Altium Designer Viewer license which is valid for a 6 months.

Please fill out the form below to request one.

By clicking “Get Your Free Trial”, you are agreeing to our Privacy Policy.
You may receive communications from Altium and can change your notification preferences at any time.