nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

Question regarding alternative paths #412

Closed lyndonlim27 closed 1 year ago

lyndonlim27 commented 1 year ago

In the textbook it says that it is acceptable for none of the alternative partitions to be executed. But I thought alternative paths is like an if else statement where it is guaranteed to execute one and only one partition.

image
nramapurath commented 1 year ago

I was wondering if perhaps the partitions' executions are optional to account for the scenario of an 'if-else if' without a closing 'else'? In that case, if none of the conditions match then none of the partitions would be executed.

damithc commented 1 year ago

@lyndonlim27 Unlike in activity diagrams in which exactly one path needs to be taken (or else the execution gets stuck), it is fine in alt frames to not execute any partitions. This gives us more flexibility, as there are cases which none of the conditional code blocks are executed e.g., switch-case with no default branch (and the example @nramapurath mentioned).

lyndonlim27 commented 1 year ago

I see. Thank you prof!