| 281 | | === `$choose` |
| | 281 | === Nondeterministic selection statement `$choose` |
| | 282 | |
| | 283 | A `$choose` statement has the form |
| | 284 | {{{ |
| | 285 | $choose { |
| | 286 | stmt1; |
| | 287 | stmt2; |
| | 288 | ... |
| | 289 | default: stmt |
| | 290 | } |
| | 291 | }}} |
| | 292 | The default clause is optional. |
| | 293 | The guards of the statements are evaluated and among those that are true, one is chosen nondeterministically and executed. |
| | 294 | If none are true and the default clause is present, it is chosen. |
| | 295 | The default clause will only be selected if all guards are false. |
| | 296 | If no default clause is present and all guards are false, the statement blocks. |
| | 297 | Hence the implicit guard of the `$choose` statement without a default clause is the disjunction of the guards of its sub-statements. |
| | 298 | The implicit guard of the `$choose` statement with a default clause is ''true''. |
| | 299 | |
| | 300 | Example: this shows how to encode a “low-level” guarded transition system: |
| | 301 | {{{ |
| | 302 | l1: |
| | 303 | $choose { |
| | 304 | $when (x>0) {x--; goto l2;} |
| | 305 | $when (x==0) {y=1; goto l3;} |
| | 306 | default: {z=1; goto l4;} |
| | 307 | } |
| | 308 | l2: |
| | 309 | $choose { |
| | 310 | ... |
| | 311 | } |
| | 312 | l3: |
| | 313 | $choose { |
| | 314 | ... |
| | 315 | } |
| | 316 | }}} |