Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 what is a boolean
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jimbo1991




PostPosted: Tue May 27, 2008 10:05 am   Post subject: what is a boolean

what exactly is a boolean?
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: 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
isaiahk9




PostPosted: 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.
Hendo




PostPosted: 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
code:
if boolvar1 = true then
x=x+1
else
%if its not true
x=x-1 %do this instead
end if
Reality Check




PostPosted: 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.
Mackie




PostPosted: 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.
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mackie




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: