Short circuit logic
|
04-18-2020, 08:17 AM
Post: #1
|
|||
|
|||
Short circuit logic
I found that I can replace IFs with short circuit logic. Example:
IF a>b THEN do_something; do_something_else; END; can be replaced by: (a>b) AND (do_something; do_something_else); as long as do_something and do_something_else are only calls to other functions or assignments. There must not be statements like IFs, RETURNs, BEGINs, loops... But if this is a really long line the Prime finds an error in it. Any thoughts? |
|||
04-18-2020, 11:06 AM
Post: #2
|
|||
|
|||
RE: Short circuit logic
My thoughts:
With tools, such as IF THEN ELSE END; and IFTE(); which are designed to accomplish this task, there is little to be gained by using the shortcut. Considering the programming effort overall, avoiding unusual syntax, (which might have unintended side effects directly, or in other releases), seems like a more dependable choice. |
|||
04-18-2020, 11:35 AM
Post: #3
|
|||
|
|||
RE: Short circuit logic
It is for the sake of simplification, in a logical operation when using "AND", if the first value is false it will obviate the following values โโof the same level, because in an "AND" operation, a false is enough for everything to be false.
This is a valid alternative: Boolean_real AND Function_or_ (operation) "Function" or "Operation" must return a real or integer number, because logical operators only accept those values. (operation1; operation2; ...): This is a syntax error Examples of argument error: Boolean_real AND Complex --- bad Boolean_real AND String --- bad Boolean_real AND Unit --- bad ... Viga C | TD | FB |
|||
04-18-2020, 11:39 AM
(This post was last modified: 04-18-2020 11:54 AM by Carlos295pz.)
Post: #4
|
|||
|
|||
RE: Short circuit logic
(04-18-2020 08:17 AM)mchris Wrote: IF a>b THEN In logical operation format it would be like this:: (a>b) AND (do_something) OR (do_something_else); Knowing that do_something and do_something_else must return a real or integer otherwise an error occurs in execution. do_something must return a value other than 0 Example: Code: EXPORT LogicExpr(Boolean) Viga C | TD | FB |
|||
04-18-2020, 07:52 PM
Post: #5
|
|||
|
|||
RE: Short circuit logic
(04-18-2020 11:06 AM)DrD Wrote: My thoughts: Right! IFTE is the way to go here! โ โ VPN |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)