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
- Create a String variable called input. Select Sequence as its Scope.
- Create an Integer variable called intNum. Select Sequence as its scope.
- Add an InputDialog activity in the Sequence, and in the Result field in the Properties, add input.
- In the InputDialog Title field, write "Odd or Even", and in the Label field, write "Enter a number:".
- After the InputDialog activity, insert an Assign activity.
- 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.
- 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.
- Click Add An Activity in the Default case and then add a Write Line activity.
- In the Text field, write intNum.ToString + " is an even number.". This means if the expression returns 0, it's an even number.
- Click Add new case and in the Case value field, write 1.
- Add a Write Line activity inside Case 1.
- 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.