How does the compiler handle case statements?

The documentation in the case reports, it says:

Each value represented by caseList must be unique in the case of an expression;

And an example is shown,

case I of
  1..5: Caption := 'Low';
  6..9: Caption := 'High';
  0, 10..99: Caption := 'Out of range';
else
  Caption := ;
end

equivalent to a nested conditional:

if I in [1..5] then
  Caption := 'Low';
else if I in [6..10] then
  Caption := 'High';
else if (I = 0) or (I in [10..99]) then
  Caption := 'Out of range'
else
  Caption := ;

So, the first quote suggests that it is treated as a set (read the comments here at least one person with me on this).

Now i know the part

where selectorExpression is any ordinal expression less than 32 bits

contrary to a number of properties, as mentioned it at sets:

The base type can have no more than 256 possible values, and their orders must be between 0 and 255

, , caseList. if, , ?

+4
2

case, if.

case if, . .

if ( ) case. , .

case ?

, .

  • case, . :
    • , caseList .
    • , caseList .
    • , caseList , caseList-.
    • caseList , else.
  • , , / .

, , caseList.

. caseList- , ?

  • caseList- . ( SQL Server CASE .) . [1].
  • . ( , MANTIS case case.)
  • , caseList. ( , , Delphi. . , , .)

if, , .

[1] , . "" , . , , caseList-, caseList, . , case - caseList.

const
  NEW_CUSTOMER = 0;
  EDIT_CUSTOMER = 1;
  ...
  CANCEL_OPERATION = 0;

case UserAction of
  NEW_CUSTOMER : ...;
  EDIT_CUSTOMER : ...;
  ...
  CANCEL_OPERATION : ...; { Compiler error is very helpful. }
end;

. , caseList , , " ". . , , .

, . . , . , . , , .

+10

case case
case .
, , .

, case , . ; , , case.

( ), case .

if
A (), , .
( , ).
if , , case, , , .
.


256 - .
256 = 32 .
256 , .

case , .

+6

Source: https://habr.com/ru/post/1672658/


All Articles