

In this case you would preferably put two fragments, one with the correct operation guard and the second one with a condition that should cause a break. Whatever flow is after the combined fragment is executed normally anyway. If you want to show control structures like this, you are better off with an activity diagram or indeed with code itself. The first thing to point out is that this isn’t what sequence diagrams are good at.
#Uml sequence diagram loop how to
There might be also a situation when none of the guards evaluate to true and no fragment is executed in such case. A common issue with sequence diagrams is how to show looping and conditional behavior. When an alt combined fragment is met its guard conditions are evaluated and only the eventual one fragment which guard evaluates to true is executed. If any additional actions should happen in case of a break, they should be put after the opt combined fragment. The opt fragment should have a guard that is opposite to the condition at which the flow should stop. You can put the part of the flow that is continued only if the break condition is not met inside the opt combined fragment. The rest of a flow continues regardless of the condition. When an opt combined fragment is met it executes only if a guard condition is true. In this case you would put the messages that shouldn't be executed in case of a break condition after the break combined fragment. If the condition is not met, the combined fragment is omitted and the normal flow continues. When a break combined fragment is met and its guard condition is true, only this fragment is still executed and then the execution of the interaction (flow) stops. However each of them provide you a valid possibility. The first solution is the most convenient one - it exactly covers your case and you can also use the positive version of a break guard. The actual behaviour is hidden with interaction references (normalFlow for a flow that should normally be executed and breakFlow for any flow that should happen in case of a required break). Each of them I illustrate with a diagram showing how the respective combined fragment should be used.

There are three options for this situation.
