Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Making decisions based on user string. (http://www.alice.org/community/showthread.php?t=10437)

 kolz 12-28-2013 11:12 PM

Making decisions based on user string.

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 12: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.

[B]if[/B] true
object say YES...
[B]else[/B]
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:
[B]1 [/B] nesting another if else clause

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

[B]2[/B] extend the logic
[B]if[/B] 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.

 All times are GMT -5. The time now is 03:25 AM.