Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Split 'if' works wrong for OR condition #461

Open
amirhalatzi opened this issue Mar 2, 2015 · 2 comments
Open

Split 'if' works wrong for OR condition #461

amirhalatzi opened this issue Mar 2, 2015 · 2 comments

Comments

@amirhalatzi
Copy link

Split 'if' for (cond1 || cond2) condition should be
if(cond1){}
if(cond2{}

Currently:
if(cond1){}
else if(cond2){}

@Rpinski
Copy link
Member

Rpinski commented Mar 2, 2015

But what if both conditions are true? Then both if blocks would be executed, which is not equivalent to original "if (cond1 || cond2)". The "if" + "else if" is correct in my opinion. Do you have any example showing that "else if" is wrong?

@siegfriedpammer
Copy link
Member

In terms of block execution @amirhalatzi is right. But in the case of cond1 || cond2 cond2 should only be evaluated if cond1 returned false.

Consider the following example:

Result r;
if (LoadFromSource(a, out r) || LoadFromSource(b, out r))
    Process(r);

Would be turned into:

Result r;
if (LoadFromSource(a, out r))
    Process(r);
if (LoadFromSource(b, out r)) // what if r was already loaded from the first source?
    Process(r);

Which could lead to undesired side effects...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants