如何在时序图中表示“do while”控制结构?

How do you represent a do while control structure in a sequence diagram?

我能想到的唯一解决办法是在循环之前创建一个变量,以便它可以第一次进入。但是,我认为这不是最佳选择。

loop fragment中的约束允许写任何东西。而不是使用变量的内容,您应该以明文形式表达数字来解释循环的原因。在任何情况下:应避免图形化编程。仅用于表达一些复杂的结构,而不是针对每一位。

交互中(通过序列图显示)支持循环的自然方式是使用组合片段与操作数loop.

formal/2017-12-05 §17.6.3.17 循环中所述(来自第 584 页):

The Guard may include a lower and an upper number of iterations of the loop as well as a Boolean expression. The semantics is such that a loop will iterate minimum the ‘minint’ number of times (given by the iteration expression in the guard) and at most the ‘maxint’ number of times. After the minimum number of iterations have executed and the Boolean expression is false the loop will terminate.

while 相反,在 do-while 的情况下,测试在循环的末尾,另一个可以说测试(没有副作用)是在循环开始时完成的,但第一次没有考虑到它的结果,这正是组合片段 loop[=31 的语义=] 'minint' 的值为 1(但 0while 的情况下)和 'maxint ' 评估 *(表示无限制,请参阅第 586 页的 §17.6.4.9)=> 循环操作数的表示法是 loop(1,*) 并且布尔表达式是 while[= 的测试31=].