Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





start true, stay false

August 2nd, 2006 . by polyGeek

If you have the need to set a Boolean to be true only if every condition is met but false if it fails just once then try this:

var test:Array = [true, true, true, false, false, true, false, true];
var isAllTrue:Boolean = true;
for(var i:Number = 0; i < test.length; ++i) {

isAllTrue = ( test[i] && isAllTrue ) ? true : false;
trace(i + ” : ” + isAllTrue);

}

Output:
0 : true
1 : true
2 : true
3 : false
4 : false
5 : false
6 : false
7 : false

Notice that part of the trinary condition is isAllTrue. That way if isAllTrue ever switches to false the condition will be false thereafter.

This instance isn’t a great example because in this case you would probably want to break out of the loop as soon as your condition was false. There’s no need to keep going through the loop.

If you find a more appropriate use for this snippit let me know.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

   Welcome back (Change)

Leave a Reply

comment feed RSS   subscribe to this comment thread

Recent Posts

   



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud