Alice Community  

Go Back   Alice Community > General Discussion > The Lounge

Reply
 
Thread Tools Display Modes
Loop While If/Else Lab2
Old
Derrick James
Guest
 
Status:
Posts: n/a
Default Loop While If/Else Lab2 - 04-09-2009, 07:04 AM

First off I think Im starting to have fun with this now. Second there a few ways to achieve the same ultimate goal as far as having the program start again if answer was yes. I immediatley thought of (if/else) :
if \askuserfor data string\ = Yes; yes;YES etc.(Nested)
Else (myfirstworld) which called to everything.
Which would work but no loop like the assignment called for. The next step was to use variables to act as on or off 0 or 1 which could then be set as the number of times to loop (myfirstworld). not really sure if thats what was called for but I made it work depending on the outcome of the if/else statement.

I attempted to go further by allowing for typos or if the user said no No or NO. I was getting close but I just had too many loops and if/else statements so i deleted them. I'm sure that there was a simpler solution.
   
Reply With Quote
Old
HisWorld
Guest
 
Status:
Posts: n/a
Default 05-04-2009, 11:02 PM

try comparing it to a list with your different spellings, this should simplify things considerably
   
Reply With Quote
Compare to list?
Old
Derrick James
Guest
 
Status:
Posts: n/a
Default Compare to list? - 05-07-2009, 11:15 AM

How would I do that? Is this the same thing as lists and arrays.
Just thinking here but could i make a variable for each of no No NO or anything for that matter and then create if/else that is or is not equal to the variables as an array or list?
   
Reply With Quote
Old
HisWorld
Guest
 
Status:
Posts: n/a
Default 05-08-2009, 10:41 AM

You could make a seperate variable of type string and compare them, I havn't verified this in Alice, but I have defiently done this in Java. I think the equivalent in java is strcomp("....","....") but in alice probably just ==. Making a list would be simpilier and prefill it will the different no's

Lists, array's, stacks, file's are all different way's of organizing a group of usualy related data. Lists and array's are nice because you can usually access any part of the list, In stacks "FILO" only the last item of data stored can be accessed , in file"FIFO", only the first one stored.


scott300 has posted a game that utilizes lists in alice

Last edited by HisWorld; 05-08-2009 at 10:42 AM. Reason: inserted hyperlink
   
Reply With Quote
Reply

Tags
loop while if/else lab2

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.