| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Nested if (SomeCondition) blocks https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1367 |
Page 1 of 1 |
| Author: | SteveHopwood [ Tue Jan 08, 2013 7:46 am ] |
| Post subject: | Nested if (SomeCondition) blocks |
Lifesys has introduced me to the joys of nested if (SomeCondition) blocks. They are really cool. From the gms' Double Big Mac V7 mod Steve EA: Code: Select all |
|
| Author: | mobthehop [ Tue Jan 08, 2013 10:07 am ] |
| Post subject: | Re: Nested if (SomeCondition) blocks |
Thanks Steve & lifesys - wondered for the longest time how to do 2 or more conditions ( a la "ducks in a row") as basis for a trade decision Cheers |
|
| Author: | dietcoke [ Tue Jan 08, 2013 12:02 pm ] |
| Post subject: | Re: Nested if (SomeCondition) blocks |
This is absolutely the way to code multiple conditions because if you put multiple conditions in a single if statement, Empty4 always tests ALL the conditions even if the first one fails. |
|
| Author: | garyfritz [ Wed Jan 09, 2013 5:55 pm ] |
| Post subject: | Re: Nested if (SomeCondition) blocks |
You can do this as a single "if" with a complex condition, e.g.: Code: Select all But minor little things like efficiency of the compiled code really aren't worth worrying about. A much bigger deal is the "lazy evaluation" DC's talking about. Where most of those tests are calling functions, each of the tests might be an expensive operation. The single-if code using && evaluates ALL of those functions, even if the very first test fails. The multiple-if code quits as soon as one of them fails. That might save you quite a bit. One thing to remember: the "then" part of an if is a single "statement," whether that's one actual statement or a compound statement in {}'s. Each if is considered a single "statement," no matter how complex the logic is inside the "then" part, so in this construct you don't need {}'s around the "then" parts. That looks cleaner in this nested-if test. But be careful about omitting {}'s in code that you might add to later, like this: Code: Select all |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|