Computer Science Canada ands and ors in ifs |
Author: | Jonny Tight Lips [ 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. |
Author: | Token [ Thu Feb 17, 2005 7:27 pm ] |
Post 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 |
Author: | Drakain Zeil [ Thu Feb 17, 2005 7:31 pm ] |
Post 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. |
Author: | TheZsterBunny [ Thu Feb 17, 2005 7:35 pm ] | ||||||
Post subject: | |||||||
sometimes this part can be a bit confusing. Most languages identify an if statement as a boolean value i.e.
if you are going to have multiple statements, why not bracket them about? i.e.
will have a completely different effect than
it also makes alot more sense when reading it. never trust the order of operations. -Z |
Author: | Jonny Tight Lips [ Fri Feb 18, 2005 8:22 pm ] |
Post subject: | |
AH HA! Brackets. That the key. I didn't know you could use brackets in ifs. That makes life easyer. Thanx a lot!! ![]() |
Author: | person [ Sun Feb 20, 2005 11:25 am ] |
Post subject: | |
now for the brackets, dont do: if var1 = (var3 or var4) then %watever end if |
Author: | ssr [ Sun Feb 20, 2005 9:26 pm ] |
Post subject: | |
I remember learning this in school first"not" then, "and" then comes "or" ![]() try it |