1. Re: Short Circuiting
- Posted by Andy Kurnia <akur at DELOS.COM> Jun 25, 1998
- 506 views
>Date: Wed, 24 Jun 1998 13:22:38 CDT >From: Lewis Townsend <keroltarr at HOTMAIL.COM> >Subject: Re: Short Circuiting > >I must agree with Isaac here, I don't want my code to be broken just for >some one elses convenience. Killing existing code is a much too great >of a sacrifice just to make new code more compact. I don't understand >short-circuiting very well but code that uses it seems very complicated >and unclear, bordering on the illogical. I don't want my programs >smashed just to support this kind of code. Another Ralf-like way to say, "new feature? no!" You don't understand SC, well it's not very complicated, it is VERY clear. It works as follows, you evaluate left to right, and as soon as the results can be determined it stops and you don't need further evaluation. if A() and B() and C() then -- assume short-circuit A() will be evaluated no matter what. If A() is 0, and "0 and XXX" will always be 0 no matter what that XXX is, B() and C() are not evaluated, and the entire expression is false (0). On the other hand if A() is NOT 0, B() is evaluated. If B() is 0, C() will not be evaluated and the entire expression is false. Otherwise it returns whether C() is nonzero or not. if A() or B() or C() then -- short-circuit A() will always be evaluated. If A() is NONzero, and "nonzero or XXX" will always be true, B() and C() are not evaluated, and the entire expression is true (1). Else, B() is evaluated, if it's nonzero the entire expression is true and C() is not evaluated. Else, it will tell you if C() is nonzero or not. See? Very logical.