Code archives/Algorithms/k.i.s.s. toggle

This code has been declared by its author to be Public Domain code.

Download source code

k.i.s.s. toggle by Russell2001
Probably the absolute easiest way to toggle between two numbers.
;Toggle between 0 and 1:
a = 0
Repeat
  Print a
  a = 1 - a ; <- The clever part!
Forever

; Learned this from waaaaaaaay back in the
; Commodore 64 days... 

Comments

aCiD22004
its even easier to jsut do a = not a :)


Damien Sturdy2004
Haa, but "a=not a" only works with the value 1.

a=64-a toggles between 0 and 64


@rtur2004
A little faster method:

a = a xor 1


Inner2004
@rtur: please remove that thing in your sig which displays IP my ISP and my operating system + which version of IE.


N2004
Yeah, @rtur. It goes over the recommended forum signature size: 80 pixels or 5 lines, if I recall correctly.


Inner2004
not to mention an invasion of my privacy, who knows what else that thing is doing.


Dreamora2004
It is only analyzing the the data your browser is sending. that's what every page statistic knows as well.


TomToad2004
Wouldn't it be faster to do

Repeat
Print 0
Print 1
Forever


N2004
TomToad: ... You missed the whole point I'm guessing.


@rtur2004
2 Inner
It show all info only to u...no one else know your ip,isp etc...;-)


Warren2004
Could you still remove it, please? It's huge and annoying.


Damien Sturdy2004
...i like it. but i suppose if its anoying people, best to stay in the good books.


puki2004
"@rtur" doesn't appear to be doing it himself - looks like he is accessing the info via a 3rd party and relaying it in - I don't think it is malicious, but I would be a bit concerned that the data is being collated by a 3rd party website that he has nothing to do with.


Inner2004
@rtur: I don't care, if it's telling me my entire life history, remove it please.


Rook Zimbabwe2004
3rd party can also grab email from outlook (and a few other mailbox programs as well now...) create SPAM for all... BAD @rtur... BAD... PLease remove it!
oh and:
musicflag=1
annoy=LoadSound("anoy1.ogg")
LoopSound annoy
Global play_annoy=PlaySound(annoy)

while not keyhit(1)

If KeyHit(50)>=1 Then musicflag=1-musicflag

If musicflag=1 Then ChannelVolume play_annoy,0.4 Else ChannelVolume play_annoy,0

wend
This is how I use that toggle. Wolron and MAtty both showed me how to do this... it could be modified for any key on the keyboard to control anything... haven't tried it with combos yet! :]

-Rook Zimbabwe


TomToad2004
Hmm, weird. I tried a benchmark using
musicflag = 1 - musicflag

and
musicflag = not musicflag

and the first version seems to be faster.


Warren2004
I doubt this is going to be your primary bottleneck, guys.


@rtur2004
ok ppl, i've removed it...

it was just fun signature..no collecting emails for spam or other bad things...just fun...:-(


Rook Zimbabwe2004
Thank you @rtur. I appreciate that you listened.


Code Archives Forum