Alice Community  

Go Back   Alice Community > General Discussion > The Lounge

Thread Tools Display Modes
Lab 2
Junior Member
Status: Offline
Posts: 12
Join Date: Jul 2018
Default Lab 2 - 07-23-2018, 05:52 PM

I was able to accomplish what was asked.. I think.. mostly. The character asks the user how many times you want him to spin. You put in the number. That number is plugged into a variable that is then fed into a loop that makes him spin the specified number of times. Viola. The instructions did state to use a loop to make the program execute again but I told the method to call itself if the user answers yes, Yes, of YES when asked if they would like to continue. I nested if/then statements with the true spot taken by a variable I made called answer to save the response of the user as a string. If yes, Yes, or YES is the answer the method will call itself and start again. If no or anything else is input nothing happens and it doesn't restart.

Recursive method calls is what the warning message said. I'd never heard of that but based on the context I figured it means when you tell a method to call itself in that same method. I was like "Yeah, go ahead." It works how I wanted it to. I imagine such things could crash the program if allowed to run out of control.

I like that it's all done in one method. It looks nice.
Reply With Quote
Junior Member
Status: Offline
Posts: 13
Join Date: Jul 2018
Default 07-30-2018, 03:11 PM

I successfully did the same thing as you except I used while for looping rather than the plain loop therefor I only had give what do if the statement was true, for anything else the program stops. I can see how this is called recursion because it closely related to the mathematical definition / concept of recursion. Recursion occurs in mathematical sequences when the outcome of the next term in the sequence is based from the terms preceding it. Just like first event (first term) is asked to repeat yes or no.The second event (second event) is dependent on the event before it (the first term)...
Reply With Quote

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.