Author |
Message |
chelsee
|
Posted: Sat Dec 09, 2006 8:52 pm Post subject: Boolean |
|
|
Im trying to figure out how to use boolean and it isn't working Could someone help me or give me an example code? thanks[color=green][/color] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Clayton
|
Posted: Sat Dec 09, 2006 8:55 pm Post subject: (No subject) |
|
|
Hello, and welcome to CompSci.ca!
Your question is answered here in the Turing Walkthrough. If you still don't find what you are looking for, keep looking through tutorials in the Turing Walkthrough, or post back here with example code of your problem, as well as a description of the problem. |
|
|
|
|
|
Prince Pwn
|
Posted: Mon Dec 11, 2006 12:18 am Post subject: (No subject) |
|
|
code: |
var lighton : boolean
lighton := true
if lighton = true then
put "The light is on."
else
put "The light is not on."
end if
lighton := false
if lighton = true then
put "The light is on."
else
put "The light is not on."
end if
|
|
|
|
|
|
|
Prince Pwn
|
Posted: Mon Dec 11, 2006 12:23 am Post subject: (No subject) |
|
|
Also, I recommend adding break to trace your code so you can see what your program is exactly doing in slow motion. |
|
|
|
|
|
Tony
|
Posted: Mon Dec 11, 2006 9:29 am Post subject: (No subject) |
|
|
actually it works like
code: |
var lighton : boolean := true
if lighton then
put "The light is on."
else
put "The light is not on."
end if
|
and I think the following works as well
code: |
put "is 2 more than 1? : ", 2 > 1
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Hackmaster
|
Posted: Mon Dec 11, 2006 8:51 pm Post subject: (No subject) |
|
|
Quote:
and I think the following works as well
Code:
put "is 2 more than 1? : ", 2 > 1
how would this work, tony? would you put a variable after this to set it to trur? or would this just put true on the screen? or... I don't know... I cuold just be missing the obvious... but... could you explain?
[/quote] |
|
|
|
|
|
Clayton
|
Posted: Mon Dec 11, 2006 8:55 pm Post subject: (No subject) |
|
|
because 2 > 1 is a boolean statement (it is either true or false right?) it counts a a boolean. So in this case, true would be output onto the screen. |
|
|
|
|
|
Tony
|
Posted: Mon Dec 11, 2006 9:24 pm Post subject: (No subject) |
|
|
Freakman is right. Any boolean operator (<=, and, or, not, etc) evaluate to a boolean value. Since put is not strictly typed, it will grab a string equivalent of the boolean value (so ether "true" or "false") and put that on the screen.
an excellent example would be
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Hackmaster
|
Posted: Tue Dec 12, 2006 9:09 am Post subject: (No subject) |
|
|
Wow... that didn't seem to obvious... um... but what use is it to ouput a boolean variable to the screen? I mean... would you be able to assign that to like a variable? I'm just gonna guess here, but...
maybe? I don't know. maybe someone could explain this concept's uses, because I really can't see how this would help in most programs. |
|
|
|
|
|
Tony
|
Posted: Tue Dec 12, 2006 9:49 am Post subject: (No subject) |
|
|
Hackmaster wrote: what use is it to ouput a boolean variable to the screen?
What use is it to output any variable to the screen? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Clayton
|
Posted: Tue Dec 12, 2006 10:20 am Post subject: (No subject) |
|
|
@Hackmaster: can you assign any variable as you did? No, not that way. Instead, you just assign a boolean variable like any other variable. |
|
|
|
|
|
Hackmaster
|
Posted: Tue Dec 12, 2006 2:41 pm Post subject: (No subject) |
|
|
Alright, thanks... I just can't really see where it would help in a program, outputting true or false for the user to see. |
|
|
|
|
|
Clayton
|
Posted: Tue Dec 12, 2006 3:56 pm Post subject: (No subject) |
|
|
maybe not necessarily for the user to see, but for debugging purposes it is very useful. |
|
|
|
|
|
|