03-29-2006, 05:01 PM
Quote:na_th_an Wrote:Moneo Wrote:Ralph Wrote:In the spirit of the originally stated "to turn a switch on and off", would the very often used following line qualify?Yeah, that works Ralph, but we have been considering as algorithms that code which does not have any IF's. That is, strictly computational, either arithmetic or logical.
Code:IF A = 1 THEN A = 0 ELSE A = 1
*****
Code:A = 1 - A
Yeah, Nathan, that's very good. But we should always define that this algorithm will flip a switch which is either 0 or 1. BTW I forgot to mention this in the examples of the original rules of the thread.
NOTE: Speaking of those examples, the following code is incorrect for flipping a 0 or 1 switch called sw:
sw = sw xor sw
It should be:
sw = sw xor 1
I'm surprised nobody caught that.
*****
Sure, that's what it does. Flip 0 to 1, 1 to 0... It was just an oneliner for the multiline IF version.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i