Description

Creates a loop that executes activities within a sequence while the condition is met.



Attributes

Misc

  • DisplayName - Renames the activity.
  • Expression - The expression to evaluate against the collection of cases.


Example

  1. Create a String variable called input. Select Sequence as its Scope.
  2. Create an Integer variable called intNum. Select Sequence as its scope.
  3. Add an InputDialog activity in the Sequence, and in the Result field in the Properties, add input.
  4. In the InputDialog Title field, write "Odd or Even"and in the Label field, write "Enter a number:".
  5. After the InputDialog activity, insert an Assign activity.
  6. In the Assign activity To field, add intNum variable, and then in the Value field, write Int32.Parse(input). This will convert the string input to an integer.
  7. After the Assign activity, add a Switch<Int32> activity and set the Expression to intNum mod 2. This expression gets the result of intNum modulo 2.
  8. Click Add An Activity in the Default case and then add a Write Line activity.
  9. In the Text field, write intNum.ToString + " is an even number.". This means if the expression returns 0, it's an even number.
  10. Click Add new case and in the Case value field, write 1.
  11. Add a Write Line activity inside Case 1.
  12. In the Write Line Text field, write intNum.ToString + " is an odd number.". This means if the expression returns any number besides 0, it's an odd number. 

    The use case should look like the following screenshot:



If the user enters an even number, the output should look like this in the Output panel:


Expected output for Even values


Otherwise, this should be the output:


Expected output for Odd values


IMPORTANT NOTE:

If you would be using a String for the Switch activity, you would no longer have to enclose the String inside quotation marks whenever stating String Cases.