Answer - Control Flow Activities
- 1If Activity: Conditional branching. Condition → Then branch / Else branch. Example: If age >= 18 Then "Adult" Else "Minor"
- 2Switch Activity: Multi-way branching. Evaluates expression, executes matching case. TypeArgument specifies data type. Has Default case.
- 3While Activity: Pre-test loop. Checks condition before each iteration. Executes body while condition is True.
- 4Do While Activity: Post-test loop. Executes body first, then checks condition. Runs at least once.
- 5For Each Activity: Iterates over collection. For Each item In collection. TypeArgument matches collection element type.
- 6Flow Decision: Flowchart equivalent of If. True/False branches. Used in flowchart workflows.
Factorial Program using For Each
Factorial Calculation Workflow
Variables:
n : Int32 (input number)
result : Int64 = 1
numbers: List<Int32>
Steps:
1. [Input Dialog] → Get n from user (e.g., n = 5)
2. [Assign] numbers = Enumerable.Range(1, n).ToList()
→ Creates list: {1, 2, 3, 4, 5}
3. [For Each] num In numbers (TypeArgument: Int32)
│
└── Body: [Assign] result = result * num
Iteration 1: result = 1 * 1 = 1
Iteration 2: result = 1 * 2 = 2
Iteration 3: result = 2 * 3 = 6
Iteration 4: result = 6 * 4 = 24
Iteration 5: result = 24 * 5 = 120
4. [Message Box] "Factorial of " + n.ToString + " = " + result.ToString
→ Output: "Factorial of 5 = 120"
Alternative using While:
─────────────────────────
i = 1, result = 1
While (i <= n)
result = result * i
i = i + 1
End While