forums

TNT Basic Forums > Programming Q&A
more array help
< Last Thread     Next Thread >
Author
Thread        Post A Reply

05-25-2008 18:25

Posted by:
shepherd150

Click Here to Email shepherd150   Find more posts by shepherd150

just A quick question
I have a true/false variable array. I need my program to check to see if all of the variables in that array are false. How do I make it do that?

05-26-2008 03:07

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

You could use a for . . . next loop to cycle through the array and check one at a time to see if the value is 'false'



or

You could assign 'zero' for false and 'one' for true.
Add the array values and if it equals '0' they are all false.

for example:

===============

global int x[37]
int y
int check = 0

...... stuff happens

check = 0

for y = 0 to 36
check = check + x[y]
next y

if check = 0
'everything is false
else
'something is true
end if

===============

How big is the array?

If this doesn't make sense maybe post a snippet of code containing the array in question?

cheers

barry

05-26-2008 15:41

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

How many numbers do you got?
if it isn't too big. (i.e less than 32)
you could store all the true/false values in a single number.

eg.

indices:
0 1 2 3 4 5 6 7 8 9

values

0 1 1 0 0 1 0 1 1 0

1=true,
0=false

number in binary form.
110010110

to set the value of index 4 to true, you might go...

number=Bit Set(number, 4, 1)

to get the value of boolean at index 4, you 'd go...

isTrueFalse=Bit Test(number, 4)

To test if every value is false simply check if number==0.

05-26-2008 15:42

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

to test if they are all true:

check if number==2^arrayLength

05-26-2008 18:25

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

that's a much cooler way to do it! =)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.