
-----------------------------------
Neo
Wed Nov 24, 2004 11:08 pm

ARRAYS
-----------------------------------
If I had an array with 121 variables of boolean, how would I check to
see if all of them are true?

like this but shortened
if num(1)=true and num(2)=true and num(3)=true...etc

-----------------------------------
wtd
Wed Nov 24, 2004 11:11 pm

Re: ARRAYS
-----------------------------------
If I had an array with 121 variables of boolean, how would I check to
see if all of them are true?

like this but shortened
if num(1)=true and num(2)=true and num(3)=true...etc

Use a loop.  Remember that checking to see if they're all true is the same as checking to see if any of them are false.

-----------------------------------
Hikaru79
Wed Nov 24, 2004 11:47 pm


-----------------------------------

var allTrue : boolean := true
for x: 1..121 
if num(x) = false then
allTrue := false
exit
end if
end for


-----------------------------------
wtd
Thu Nov 25, 2004 12:02 am


-----------------------------------

var allTrue : boolean := true
for x: 1..121 
if num(x) = false then
allTrue := false
exit
end if
end for


Close, but you don't need the variable.  And as long as you posted code...

function allTrue (arr : array 1 .. * of boolean) : boolean
   for i : 1 .. upper (arr)
      if not arr (i) then
         result false
      end if
   end for
   result true
end allTrue

-----------------------------------
Hikaru79
Thu Nov 25, 2004 12:09 am


-----------------------------------

var allTrue : boolean := true
for x: 1..121 
if num(x) = false then
allTrue := false
exit
end if
end for


Close, but you don't need the variable.  And as long as you posted code...

function allTrue (arr : array 1 .. * of boolean) : boolean
   for i : 1 .. upper (arr)
      if not arr (i) then
         result false
      end if
   end for
   result true
end allTrue

:oops: I stand corrected.

-----------------------------------
wtd
Thu Nov 25, 2004 12:29 am


-----------------------------------
You had the basic idea down fine.  You just weren't taking full advantage of "result".
