Computer Science Canada what is a boolean |
Author: | Jimbo1991 [ Tue May 27, 2008 10:05 am ] |
Post subject: | what is a boolean |
what exactly is a boolean? |
Author: | SNIPERDUDE [ Tue May 27, 2008 10:09 am ] |
Post subject: | RE:what is a boolean |
a boolean is a type of variable. an integer (int) holds a whole number a real number (real) hold a decimal number a boolean hold a true/false value. ex: var test : boolean := true |
Author: | isaiahk9 [ Tue May 27, 2008 3:18 pm ] |
Post subject: | RE:what is a boolean |
Booleans are useful when you only deal with two possible outcomes. Example - var isp1right : boolean := true loop if player clicks left key, then isp1right := false, p1x -= 5 elsif player clicks right key, then isp1right := true, p1x += 5 end if Draw (character, p1x, p1y, PicMerge) end loop %I used this for my fighter game - so that the character would face right and left when you press right and left. |
Author: | Hendo [ Tue May 27, 2008 7:37 pm ] | ||
Post subject: | RE:what is a boolean | ||
yeah they're very useful if you only want to execute something if the variable hold true (or not) So something like
|
Author: | Reality Check [ Tue May 27, 2008 8:20 pm ] |
Post subject: | Re: what is a boolean |
It's simply a variable with only two possible states. This is ideal for checking is a certain event has been reached and whatnot and is more ideal than using any other kind of variable because it'd use less memory. |
Author: | Mackie [ Tue May 27, 2008 8:25 pm ] |
Post subject: | RE:what is a boolean |
Actually a boolean is 8 bits, same as nat1 (Range of 0 - 255). Surprising enough, I'd think it would only be 1 bit. On or off. |
Author: | Tony [ Tue May 27, 2008 8:37 pm ] |
Post subject: | RE:what is a boolean |
a boolean, as a variable, is indeed 8 bits. If you want to use less memory though, you could use a nat1 as an array of 8 boolean values. |
Author: | Mackie [ Tue May 27, 2008 8:51 pm ] |
Post subject: | RE:what is a boolean |
That is a very smart idea! I'll have to remember that. |