Alice Community counting

 counting
 bopgaard Junior Member   Status: Offline Posts: 5 Join Date: May 2012 counting - 05-10-2012, 08:13 PM Please excuse my limited knowledge with Alice, I just started a introduction course and feel very overwhelmed with the algorithms. On one my my assignments a questions asks The following algorithm was intended to result in the numbers 10 to 1 being printed. What will it actually do? What is wrong with it, and how can it be corrected? BEGIN COUNT = 10 While count > 0 { Print count Count = Count +1 } Print "The countdown is finished." END I get the basic idea of sequence I just have a hard time understanding what the =, > { symbols mean is this algorithm. any help would be really appreciated.
 TauTrumpsPi Senior Member     Status: Offline Posts: 399 Join Date: Mar 2011 Location: The diamond layer 05-10-2012, 08:28 PM Well, I can tell you what the symbols mean, but you'll have to figure out what's wrong with it, although if you need a hint I'll be willing: 1. The "=", is referred to as the assignment operator in Java programming. It reassigns a new value to a variable. So "COUNT = COUNT + 1" would take the original value of count, add one, and then make that new value the new value of count. So, in simple terms, if COUNT was originally 1, the new value of COUNT would be 2 2. The ">" is "more than". So the loop reads, in english: While COUNT is more than 0. So, the command inside the loop will read until count is no longer > 0. 3. The "{" and "}" symbols are the open and close symbols for the loop. So if the command was Code: ```loop 5 times { print "hi" }``` "hi" would be printed 5 times. However, in this case you have a while loop, so the loop will execute until count is no longer more than 0. Hope this helps, feel free to ask if you're still having trouble. -------------------------------------------------------------------------------------------------------------------------- I have plenty of common sense. I just choose to ignore it. -Calvin and Hobbes Wondering about my Avatar? http://en.wikipedia.org/wiki/Tardigrade Wondering about my username? http://www.youtube.com/watch?v=jG7vhMMXagQ
 bopgaard Junior Member   Status: Offline Posts: 5 Join Date: May 2012 05-10-2012, 08:40 PM thank you for your help. BEGIN COUNT = 10 While count > 0 { Print count Count = Count +1 } Print "The countdown is finished." END I could be wrong but I think it should read as follows. BEGIN COUNT = 10 While count > 1 { Print count Count = Count +1 } Print "The countdown is finished." END I changed the while count > 0 to a 1 so it would stop at 1 instead of 0. hope I'm on the right track. thank you for responding.
TauTrumpsPi
Senior Member

Status: Offline
Posts: 399
Join Date: Mar 2011
Location: The diamond layer
05-11-2012, 07:10 AM

Quote:
 Originally Posted by bopgaard thank you for your help. BEGIN COUNT = 10 While count > 0 { Print count Count = Count +1 } Print "The countdown is finished." END I could be wrong but I think it should read as follows. BEGIN COUNT = 10 While count > 1 { Print count Count = Count +1 } Print "The countdown is finished." END I changed the while count > 0 to a 1 so it would stop at 1 instead of 0. hope I'm on the right track. thank you for responding.
Nope, you need to keep it at 0. When the loop starts, it check what it is at, and if it is at one, which is not more than one, it will not display the loop. Therefore, you need to keep it at 0.

Your real problem lies elsewhere, inside the loop. Think about the logic involved with the loop, inside the loop, and your statement that updates the value of the count variable.

--------------------------------------------------------------------------------------------------------------------------
I have plenty of common sense. I just choose to ignore it.
-Calvin and Hobbes

 bopgaard Junior Member   Status: Offline Posts: 5 Join Date: May 2012 05-11-2012, 07:42 PM I'm lost on this one...for now I'm going to revisit the textbook. ill check back if I come up with a solution. thanks for your help buddy.
 TauTrumpsPi Senior Member     Status: Offline Posts: 399 Join Date: Mar 2011 Location: The diamond layer 05-12-2012, 10:09 AM If you do come back and you still need another hint, notice that the update statement, the one that changes the value of the variable within the loop, adds to the value of the variable. Then notice that your loop executes when the value of the variable is larger than 0. Will the loop ever terminate while this is still the case? -------------------------------------------------------------------------------------------------------------------------- I have plenty of common sense. I just choose to ignore it. -Calvin and Hobbes Wondering about my Avatar? http://en.wikipedia.org/wiki/Tardigrade Wondering about my username? http://www.youtube.com/watch?v=jG7vhMMXagQ
 bopgaard Junior Member   Status: Offline Posts: 5 Join Date: May 2012 05-16-2012, 09:02 PM i was able to solve this problem thanks to your help. thank you for the guidance.

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge