Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
How do I make an if/else equal yes?
Old
HalBen18
Junior Member
 
Status: Offline
Posts: 12
Join Date: Jan 2014
Location: Cedar Hill, TX
Post How do I make an if/else equal yes? - 03-20-2014, 08:51 PM

I have a program where a girl asks the user how many times they want her to spin. After that, she jumps up, spins that amount and then comes down. Then I ask the user if the want the program to repeat. I need help with if they input "yes" to have it run again. If they say no, she needs to say goodbye. I can't find a yes or no equation. Then I can't figure out how to use a loop to do this so that it will run continually as long as the user keeps entering "yes" at the end. Help please?
   
Reply With Quote
Booleans
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Post Booleans - 03-20-2014, 09:22 PM

The cool thing about Boolean variables is that they can only be one of two possibilities at any given time.
So, if you create a variable called something like "running" and make it "true", you can use it anywhere there is a true/false test.
If "running"
do something
else
do something else

OR
While "running"
do a bunch of stuff over and over
and change "running to false to stop the loop

See if you can modify this code to print "true" four times before printing "false".
Don't just add three more print lines.
Instead, create a numeric "counter" and add test logic to determine when to set "running" to "false". Just a few lines of code will let you print any number of trues.
Attached Images
File Type: jpg boolean.jpg (46.5 KB, 21 views)

Last edited by MrMoke; 03-21-2014 at 07:15 AM.
   
Reply With Quote
if/else equal true
Old
levimrj
Junior Member
 
Status: Offline
Posts: 11
Join Date: Jan 2014
Location: Dallas, TX
Default if/else equal true - 03-28-2014, 02:34 PM

I did not know you could make a true false statement like that!! I just got through with my assignment of the spinning character and I used a 'while' statement. Not sure if the 'while' is preferable over the 'if/else' statement but I figured since I didn't have an 'else' for my character to do, I used the 'while' statement. Some of these assignments seem hard until I really start thinking about what I'm writing in the program and then it makes sense.
   
Reply With Quote
It's called the Logical Thought Process
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default It's called the Logical Thought Process - 04-10-2014, 03:24 PM

It's what programmers do

Click and Open the attached Movie
Attached Files
File Type: zip Spinner.zip (19.96 MB, 6 views)
   
Reply With Quote
Reply

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 ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.