Recent

Author Topic: Syntax curiosity  (Read 8397 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14169
  • Probably until I exterminate Putin.
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.
Specialize a type, not a var.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
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.

 

TinyPortal © 2005-2018