Some inference observations

{$APPTYPE CONSOLE}
program Project2;

begin
  var vip  := true;
  var tax  := 1.5;

  var Total := 100 + if vip then 10 else 0 + tax;

  var z := 2;
  var X := if vip then 1 else z;
  var Y := if vip then 1 else 0;

  writeln(total:5:3);
  readln;
end.

I was in conversation with Claude, and a couple questions came up … which I/we tested.

Is …
a) Total := 100 + if vip then 10 else (0 + tax) ?
b) Total := 100 + (if vip then 10 else 0) + tax ?

  • It is (a)

What are the types of X and Y ?

  • X is of type Integer

  • with ‘else 0’ or similar, Y is of type [0..127]

  • with ‘else 200’, Y is of type Byte

  • with ‘else 1000’, Y is of type [0..32767]

  • with ‘else 40000’, Y is of type Word

  • with ‘else 2.5’, Y is of type Extended

:slight_smile:

  var Y := if vip then 1 else 2;

  for var i := 1 to 300 do inc(Y);

  writeln(Y);

This is an Integer Overflow.

:frowning:

  var s := 'hello';
  var c := if vip then 'a' else s;
  var d := if vip then 'a' else '';
  var e := if vip then 'a' else 'hello';

All these variables are of type string

:slight_smile:

  var i := 0;
  var j := if True then 0 else 1;

i is of type Integer
j is of type [0..127]

:confused: