Flow control

For flow control, Polar Script has a large number of statements available

If...Then...Else Statement

The If...Then...Else statement allows you to specify different actions to take depending on whether a condition is true or false.

If condition Then
   ' code to execute if condition is true
Else
   ' code to execute if condition is false
End If

You can also use the ElseIf keyword to specify additional conditions to test:

If condition1 Then
   ' code to execute if condition1 is true
ElseIf condition2 Then
   ' code to execute if condition1 is false and condition2 is true
Else
   ' code to execute if condition1 and condition2 are false
End If

An If-Then-Else can also be on one single line. In that case, no End If is to be used. The ElseIf is NOT supported on a single-line If statement:

If condition Then SomeAction

'or:
If condition Then SomeAction1 Else SomeAction2

For-Next Statement

The For-Next statement allows you to iterate over a range of numeric values.

For counter = start To End [Step step]
   ' code to execute for each value of counter
Next [counter]

Here, counter is a variable that is incremented for each iteration of the loop. start is the initial value of the counter, end is the final value, and step is the amount by which the counter is incremented each time through the loop (default value is 1 if not specified).

For-Each Statement

The For-Each statement allows you to iterate over set of elements in a collection or array.

For Each lLoopVariable In list
   ' code to execute for each value of lLoopVariable
Next

'For example:
Const lDayNames = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}
Dim lDayName As String
For Each lDayName In lDayNames
   SendDebug lDayName
Next

Do...Loop Statement

The Do...Loop statement allows you to repeat a block of code until a condition is true.

Do
   ' code to execute at least once
Loop Until condition

'... or ...
Do Until condition
   ' code to execute while condition is false
Loop

'... or ...
Do While condition
   ' code to execute while condition is true
Loop

'... or ...
Do
   ' code to execute at least once
Loop While condition

'... The loop can be exited using Exit Do:
Do
   'Some logic
   If SomeCondition Then Exit Do
Loop Until condition

'... You can even have an 'endless loop' (without any While / Until) and only rely on the Exit Do:
Do
   'Some logic
   If SomeCondition Then Exit Do
Loop

While Statement

The While statement allows you to repeat a block of code while a condition is true. The While-Wend construction is deprecated. It is advised to use a Do While - Loop construction instead. While - Wend is only available for backwards compatability with VBscript.

While condition
   ' code to execute while condition is true
Wend

Select Case Statement

The Select Case statement allows you to perform different actions based on the value of an expression.

Select Case expression
Case value1
       ' code to execute if expression = value1
Case value2
       ' code to execute if expression = value2
Case Else
       ' code to execute if expression is not equal to any of the other values
End Select