Computer Science Canada

False, but only on every other iteration...

Author:  Matt_872000 [ Tue Jun 07, 2005 10:36 am ]
Post subject:  False, but only on every other iteration...

How would I make it so that a boolean variable is false on every odd iteration of an infinite loop?

Author:  Tony [ Tue Jun 07, 2005 10:50 am ]
Post subject: 

if i is your counter then
boolean:= (i mod 2 = 0)

Author:  [Gandalf] [ Tue Jun 07, 2005 3:49 pm ]
Post subject: 

Woah... How would that work? An explanation please.

Author:  Tony [ Tue Jun 07, 2005 4:56 pm ]
Post subject: 

I'll just show you a sample
Turing:

for i : 1 .. 10
    put "iteration value: ", i, " -- boolean value: ", i mod 2 = 0
end for

The problem asks for boolean value to be false for odd numbers. Which translates into true for even numbers. Even numbers are defined as having a remainder of 0 when divided by 2.


: