PDA

View Full Version : Making decisions based on user string.


kolz
12-29-2013, 12:12 AM
Bonus question on a previous assignment was to find a way to use a range of possible strings entered by user to re-run the program. I could not figure it out, but I would really like to know how to do it.

Any tips? Thanks

Ygzaw
12-29-2013, 01:07 AM
You can use the "either a or b, or both" function in the if else.
Let's say you have a string variable called abString. And you have a an object that needs to says YES if abString is "ab","aB","AB", or "Ab" and says NO when it is something else.

if true
object say YES...
else
object say NO

Replace 'true' by dragging function "either a or b, or both." Then replace 'a' and 'b' by abString== ab and by abString ==aB.

The above has covered the two possible strings to add the other two you can use two methods:
1 nesting another if else clause

if either abString == ab or abString == aB, or both
object say YES
[B]else[B]
if either abString == AB or abString == Ab, or both
object say YES
else
object say NO

[B]2 extend the logic
if either(either(either abString == ab or abString ==aB, or both) or abString == AB) or both) or abString == Ab, or both

object say YES
else
object say NO


I added the parenthesis for clarity.
I hope I have not complicated it more.