case语句执行步骤

Case statement execution steps

我有以下案例陈述:

A = 1

case A is                      
    when 1          => A = 2;
                    => Run;      
    when 3 .. 15    => null;   
    when 16 | 17    => Jump;    
    when 2 | 18..35 => Swing;     
    when others     => Nothing; 
end case;

所以case语句会转到1,因为A初始化为1。A会等于2,然后代码会执行运行。此时代码是否退出了case语句,还是会因为A被修改为2的值而执行Swing?

根据standard, section 5.4,只有第一个when分支会被执行:

The execution of a case statement chooses one and only one alternative, since the choices are exhaustive and mutually exclusive.

从逻辑上讲,这也是有道理的,因为 case 语句的 header 中的 A 可以是任何表达式,不一定是单个变量。如果更改导致 case 表达式更改的状态可能会导致选择其他分支,则代码将变得更加难以遵循(并且该语言将成为实现的噩梦)。