Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   The Lounge (http://www.alice.org/community/forumdisplay.php?f=4)
-   -   Lab 2 (http://www.alice.org/community/showthread.php?t=12063)

Forumuser 07-23-2018 05:52 PM

Lab 2
 
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.

MBohnenstengel 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)...


All times are GMT -5. The time now is 08:29 PM.

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