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

Username:   Password: 
 RegisterRegister   
 ands and ors in ifs
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jonny Tight Lips




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Token




PostPosted: 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
Drakain Zeil




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




PostPosted: 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
Jonny Tight Lips




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




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




PostPosted: Sun Feb 20, 2005 9:26 pm   Post subject: (No subject)

I remember learning this in school
first"not" then, "and" then comes "or"
Very Happy
try it
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  [ 7 Posts ]
Jump to:   


Style:  
Search: