Recent

Author Topic: If [boolean condition] And [boolean condition]  (Read 10443 times)

wp

  • Hero Member
  • *****
  • Posts: 13269
Re: If [boolean condition] And [boolean condition]
« Reply #15 on: December 28, 2017, 12:28:31 pm »
I don't understand this answer. If I understood Munair's post correctly, he only wanted to show how IFs can be nested and he pointed out some issues that can happen to newcomers. The syntax of nested IFs does not have to do anything with bad programming.

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: If [boolean condition] And [boolean condition]
« Reply #16 on: December 28, 2017, 01:15:09 pm »
The answer was given in context. Read the parts on how to set a button enabled:
Analysis show it is a system of boolean. IMHO Munair's example works but is not correct code to solve a boolean system.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ASerge

  • Hero Member
  • *****
  • Posts: 2469
Re: If [boolean condition] And [boolean condition]
« Reply #17 on: December 28, 2017, 02:11:42 pm »
I can probably improve on this too:
Improvements need to be done more accurately ;D. The case expression will only work if the conditions are evaluated at compile time. For example, the expression (NameEdit.Text = '') is not compiled.

Thaddy

  • Hero Member
  • *****
  • Posts: 18524
  • Here stood a man who saw the Elbe and jumped it.
Re: If [boolean condition] And [boolean condition]
« Reply #18 on: December 28, 2017, 04:02:16 pm »
I can probably improve on this too:
Improvements need to be done more accurately ;D. The case expression will only work if the conditions are evaluated at compile time. For example, the expression (NameEdit.Text = '') is not compiled.
I am not sure what you mean, but:
Not if that is part of a static evaluation (as is the code) and can be eliminated by the compiler. But it is if you turn on full boolean evaluation. Careful with nitpicking.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

munair

  • Hero Member
  • *****
  • Posts: 887
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: If [boolean condition] And [boolean condition]
« Reply #19 on: December 28, 2017, 11:48:25 pm »
No Thaddy, I did not miss a point. It is you who missed the point completely. You probably overlooked the comments in my example and you definitely did not read what I said.  :D

I carefully read A's posts, and my reply was specific to his 'one last thing':
Quote from: A
Just one last thing, is there a way of making 2 things happen If [CONDITION(S)]?
So WP understood correctly.  ;)

FYI, I also did not miss A's previous threads.  8-)

But to get to your point my dear Thaddy, two IF's is equally fast or faster than combining two conditions with AND. I tested this numerous times with multiple languages.  ;D But again, it wasn't the purpose of my example to demonstrate this specifically.
« Last Edit: December 29, 2017, 12:13:44 am by Munair »
It's only logical.

ASerge

  • Hero Member
  • *****
  • Posts: 2469
Re: If [boolean condition] And [boolean condition]
« Reply #20 on: December 30, 2017, 09:30:18 am »
I am not sure what you mean, but:
I mean this
Code: Pascal  [Select][+][-]
  1. case condition of
  2.   condition1 and condition2:
  3.     begin
  4.       statemen1;
  5.       statement2;
  6.     end;
  7.   condition3 and condition4:
  8.     begin
  9.       statement3;
  10.       statement4;
  11.     end;
  12. else
  13.   statement4;
  14. end;
Conditions must be constants.

 

TinyPortal © 2005-2018