Recent

Author Topic: Syntax curiosity  (Read 2043 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 9158
Re: Syntax curiosity
« Reply #45 on: September 21, 2019, 01:45:04 pm »
Pascal has case....
but a case statement cannot be used to replace an if/else chain.
Apart from nesting: no. But there are other options that are overlooked here.
Consider:
Code: Pascal  [Select]
  1. var
  2.   i:integer = 0;
  3. begin
  4.   if i in [0..3, 7, 9, 12..15] then { do something };
  5. end.
Since i is here not a loop variable, but a plain ordinal, it is even allowed to modify it.
You can use this to construct C like switch w/o breaks for example.
also related to equus asinus.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 831
Re: Syntax curiosity
« Reply #46 on: September 21, 2019, 03:12:15 pm »
Pascal has case....
but a case statement cannot be used to replace an if/else chain.
Apart from nesting: no. But there are other options that are overlooked here.
Consider:
Code: Pascal  [Select]
  1. var
  2.   i:integer = 0;
  3. begin
  4.   if i in [0..3, 7, 9, 12..15] then { do something };
  5. end.
Since i is here not a loop variable, but a plain ordinal, it is even allowed to modify it.
You can use this to construct C like switch w/o breaks for example.
Interesting.