Conditional Statements

 

Conditional statements perform different computations or actions depending on whether a programmer-specified condition evaluates to true or false.

If

For

ForEach

Select

Switch

While

 

Examples of conditional statements:

; If statement

If x > 10

  my_variable = 'foo'

Endif

 

; If statement using AND operator

If x>0 && x<=10

   Pause( 'Result', x : ' is between 1 and 10' )

Else

   Pause( 'Result', x : ' is NOT between 1 and 10' )

EndIf

 

; If Then statement

If x > 10 then my_variable = 'foo'

 

; If Else Endif statement

If x > 10

  my_variable = 'foo'

Else

  my_variable = 'bar'

Endif

 

; For loop

For x = 1 to 5

  Pause('For loop counter', x )

Next

 

; ForEach loop

objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

; Iterater through each printer and collect

ForEach objPrinter In colInstalledPrinters

   Pause("Printer Name: ", objPrinter.Name)

Next

objPrinter = ""

colInstalledPrinters = ""

objWMIService = ""

 

; Select statement

response = AskLine("Select", "Enter a number between one and three", 1, 0)

Select response

Case 1

   Message("Select", "Case 1 entered")

   Break

Case 2

   Message("Select", "Case 2 entered")

   Break

Case 3

   Message("Select", "Case 3 entered")

   Break

Case response ; default case

   Message("Select", "Default case entered")

   Break

EndSelect

 

; Switch statement

response = AskLine("Select", "Enter a number between one and three", 1, 0)

Switch response

Case 1

   Message("Select", "Case 1 entered")

   Break

Case 2

   Message("Select", "Case 2 entered")

   Break

Case 3

   Message("Select", "Case 3 entered")

   Break

Case response ; default case

   Message("Select", "Default case entered")

   Break

EndSwitch

 

; While loop

a=10

While a>5

   Display(3, "The value of a is now", a)

   a=a-1

EndWhile

Message("The value of a should now be 5",a)

 

 

 

 

 

 

 

WIL Language Elements

Reference

Step by step guide to learning WIL

Notes