Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: If..Then..Else worth.

  1. #11

    If..Then..Else worth.

    Quote Originally Posted by User137
    Style 2 is normally faster, but style 1 is faster if B or C are slow functions or other calculations.
    You are wrong. In fact, they both will generate the same code if short-circuit Boolean expression evaluation is used (equals to "{$B-}").

    Quote Originally Posted by User137
    This may result in access violation:
    if (obj<>nil) and (obj.name='test') then
    Again, you are wrong if "{$B-}" is used (by default). In fact, if you are accessing an object (e.g. "if (obj.position.x = 25) then") and suspect that it can be nil, you can add "obj <> nil" comparison before the initial condition (e.g. "if (obj <> nil)and(obj.position.x = 25) then") to be sure.

    Of course, if you use complete Boolean expression evaluation (equals to "{$B+}"), your points are valid. I've never seen any Pascal code using complete Boolean evaluation though.

  2. #12

    If..Then..Else worth.

    Thanks... that immediately showed new way to optimize if clauses (place most frequent break conditions first).

    More about B- here:
    http://www.delphibasics.co.uk/RTL.asp?Name=$B

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •