How to draw a foreach loop on a block diagram?

foreach (Order p in order) { states[i] = new StateOrder(p.id, p.client, p.dateOrder,p.costOrder, p.haircut, p.admin); } 
  • Just as with the FOR loop, only instead of checking the counter "Is it equal to the final value?" and the action "Add one" use the check "Are there any more records?" and take next action. - Akina

1 answer 1

The same element is used as for any other cycle.

If we are talking about GOST block diagrams, then two blocks are used "3.2.2.6. Cycle boundary".

For the UML Activity Diagram, use the composite Activity with the stereotype "Loop".

If the evil teacher allows you to use only the basic blocks - expand the cycle in accordance with the specification of the language and draw a flowchart for it:

 var enumerator = enumerable.GetEnumerator(); try { while (enumerator.MoveNext()) { var current = enumerator.Current; // Тело цикла } } finally { if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose(); }