Optimization
Optimization with QB Logic
Short-Circuit Optimization

The use of any logical operator to join two truth tests is a time-honored tradition and it is perfectly *INefficient*! Most compilers, though, (which means NOT QB compilers) convert something like this:

```
IF a = 5 AND b = 7
```
to this:
```
IF a = 5 THEN IF b = 7
```

As you can see, the first case involves checking the truth values of BOTH statements and then evaluating the entire statement, while the second checks the truth value of the first, and then if it is true, checks the truth value of the second.

A logic command such as OR and AND can be easily converted to short-circuit structures. Be forewarned that EQV, IMP, and XOR do not lend themselves to this technique.

A compiler worth its salt also should convert inefficient statements to their efficient equivalents, including short-curcuit logic. Sometimes, though, it is not just a matter of efficiency but a matter of clean, easy to read, and ~PITHY~ code!

-Agamemnus

LogicChapterF - page last edited 2003-08-15 13:58:19 by 172.128.164.129 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster