Computer Science Canada Is there any command that could do this |
Author: | Kman43759 [ Wed Oct 08, 2014 4:23 pm ] | ||
Post subject: | Is there any command that could do this | ||
What is it you are trying to achieve? < I want to know if theres a command that could let me do something like var ans : string put "hi" get ans if ans = "hey" or "hi" or "hello" or "you" then put "Whats up?" end if> What is the problem you are having? <Im coding a program kind of like siri and I already explained everything above. The way im doing it is im having a seperate if for if ans = "hi", if ans = "hey, if ans = "hello", and if ans = "yo" and this is making my code really long... I wish I could just shorten this by putting if ans = "hey" or "hi" or "hello" then put "Whats up"> Describe what you have tried to solve this problem <I tried this and it did not work var ans : string put "hi" get ans if ans = "hey" or "hi" or "hello" or "you" then put "Whats up?" end if> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <4.1> |
Author: | Tony [ Wed Oct 08, 2014 5:22 pm ] | ||||||
Post subject: | RE:Is there any command that could do this | ||||||
you're almost there! an if statement (see if) is in the form of
trueFalseExpn is any expression that returns a value of true or false (also known as boolean). There is a boolean operator or that takes two boolean values, and also returns a boolean result (true if either one is true). In your example, "ans = "hey" is a trueFalseExpn, but "hello" is not. You can see the latter if we use only that part
doesn't look right. You can turn all parts into boolean expressions though!
|
Author: | Kman43759 [ Wed Oct 08, 2014 5:36 pm ] |
Post subject: | RE:Is there any command that could do this |
Thanks a lot! That really made my code alot smaller and easier to navigate |