Author |
Message |
Jonny Tight Lips
![](http://www.deftone.com/misc/johnny_tightlips.jpg)
|
Posted: Thu Feb 17, 2005 6:29 pm Post subject: ands and ors in ifs |
|
|
I just want to know how turing does the ands and ors in ifs.
For examlpe if I had:
if var1 = 2 and var2 = 3 or var3 = 4 then
does it do
var1 has to be true and var2 or var3 can be true
or
var1 and var2 have to be true or var 3 can be true
I hope you understadn what I'm talking about I know its a little confusing but I didn't know how else to explain it. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Token
![](http://server2.uploadit.org/files/token89-avatar1.jpg)
|
Posted: Thu Feb 17, 2005 7:27 pm Post subject: (No subject) |
|
|
okay, i'll try and use your example,
if var1 = 2 and var2 = 3 or var3 = 4 then
for that statement to work var1 AND var2 have to be true
or if var3 was true then it would work
the way i do it is look at each section as its own little if statement, for example
if var1 = 2 and var2 = 3 or var3 = 4 then
i separate the two different sections by the or statement. i'll give another example
if var1=1 and var2 =2 or var1 = 3 and var2 = 6 or var1 =5 then
i know its kind of confusing but what i do is say it in my head and think of it in litteral terms |
|
|
|
|
![](images/spacer.gif) |
Drakain Zeil
|
Posted: Thu Feb 17, 2005 7:31 pm Post subject: (No subject) |
|
|
if x=y then
put "blah"
end if
When turring sees x=y it evaluates for a boolean (true/false).
You can't go:
if x=y or z or l then
put "blah"
end if
Since OR evaluates between two booleans, it doesn't repeat the "x=" bit. That's how you wish it worked.
All of the math evaluation signs (>.<.=) return boolean between two values of the same type, AND, OR, return boolean from two boolean arguments, and NOT changes that boolean to it's opposite. |
|
|
|
|
![](images/spacer.gif) |
TheZsterBunny
![](http://www.members.shaw.ca/rfolz/zstervava2.jpg)
|
Posted: Thu Feb 17, 2005 7:35 pm Post subject: (No subject) |
|
|
sometimes this part can be a bit confusing.
Most languages identify an if statement as a boolean value
i.e.
code: |
var x := 5
if x = 5 then %true
end if
|
if you are going to have multiple statements, why not bracket them about?
i.e.
code: |
if x = 5 and (y = 6 or y = 12) and z = 13 then
end if
|
will have a completely different effect than
code: |
if (x = 5 and y = 6) or (y = 12 and z = 13) then
end if
|
it also makes alot more sense when reading it.
never trust the order of operations.
-Z |
|
|
|
|
![](images/spacer.gif) |
Jonny Tight Lips
![](http://www.deftone.com/misc/johnny_tightlips.jpg)
|
Posted: Fri Feb 18, 2005 8:22 pm Post subject: (No subject) |
|
|
AH HA! Brackets. That the key. I didn't know you could use brackets in ifs. That makes life easyer. Thanx a lot!! ![Very Happy Very Happy](http://compsci.ca/v3/images/smiles/icon_biggrin.gif) |
|
|
|
|
![](images/spacer.gif) |
person
|
Posted: Sun Feb 20, 2005 11:25 am Post subject: (No subject) |
|
|
now for the brackets, dont do:
if var1 = (var3 or var4) then
%watever
end if |
|
|
|
|
![](images/spacer.gif) |
ssr
![](http://siruisite.port5.com/ssr.jpg)
|
Posted: Sun Feb 20, 2005 9:26 pm Post subject: (No subject) |
|
|
I remember learning this in school
first"not" then, "and" then comes "or"
try it |
|
|
|
|
![](images/spacer.gif) |
|