Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Reply
 
Thread Tools Display Modes
Assignment 6 - Loops
Old
shaolinkidd
Member
 
Status: Offline
Posts: 17
Join Date: Jul 2015
Default Assignment 6 - Loops - 07-28-2015, 01:59 PM

I recently completed this one. We had to make a character that sang the 99 bottles of pop song all the way down to 0. We were supposed to use a 'While' statement however I could not get that to work so I didn't use it and accomplished the same goal. If you did yours with the 'While' statement, I would like to know how you did it.
   
Reply With Quote
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default 07-28-2015, 07:14 PM

Depending on the final verse either
While counter > 0
or
While counter >= 0
..sing
..dec the counter

Last edited by MrMoke; 07-28-2015 at 07:18 PM.
   
Reply With Quote
Old
CodeMan
Member
 
CodeMan's Avatar
 
Status: Offline
Posts: 36
Join Date: Aug 2013
Location: Northern Virginia
Default 07-28-2015, 08:04 PM

Quote:
Originally Posted by shaolinkidd View Post
I recently completed this one. We had to make a character that sang the 99 bottles of pop song all the way down to 0. We were supposed to use a 'While' statement however I could not get that to work so I didn't use it and accomplished the same goal. If you did yours with the 'While' statement, I would like to know how you did it.
Just curious how did you do it?


Im really RavenOfCode... shhhh....

Currently work on my first app :)
   
Reply With Quote
Old
Petit Suisse
Member
 
Status: Offline
Posts: 46
Join Date: Jul 2015
Default 07-30-2015, 02:42 AM

I'm also curious how you did it without a while statement. You're quite creative.

My solution:
http://gyazo.com/b08e6c0aa7b56d02a0fb3b09210ae065
   
Reply With Quote
loops
Old
shaolinkidd
Member
 
Status: Offline
Posts: 17
Join Date: Jul 2015
Default loops - 08-06-2015, 11:58 AM

Quote:
Originally Posted by CodeMan View Post
Just curious how did you do it?
I used a loop with a counter that incremented by 1 up to (but not including) 100 times
   
Reply With Quote
Assignment 6
Old
shaolinkidd
Member
 
Status: Offline
Posts: 17
Join Date: Jul 2015
Default Assignment 6 - 08-06-2015, 01:47 PM

Quote:
Originally Posted by shaolinkidd View Post
I used a loop with a counter that incremented by 1 up to (but not including) 100 times
See attached...
Attached Files
File Type: txt code.txt (997 Bytes, 12 views)
   
Reply With Quote
Old
RavenOfCode
Senior Member
 
RavenOfCode's Avatar
 
Status: Offline
Posts: 408
Join Date: Oct 2013
Location: Northern Virginia
Default 03-23-2016, 03:54 PM

Quote:
Originally Posted by shaolinkidd View Post
See attached...
I see, not the way I would do it but it works.


Stuff + Other Stuff + Different Other Stuff = Things :)

My best Alice game:

Clash of the Cubes (an arena fighting game):
http://www.alice.org/community/showthread.php?t=10738&highlight=game
   
Reply With Quote
Comments on the types of loops
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Comments on the types of loops - 03-25-2016, 09:38 PM

If Alice had a break statement, a programmer could write for loops that could be readily converted into a while loop or vice-versa.

Indeed this is true of all the "standard" looping constructs:
  • for
  • while
  • do ...while
  • repeat ... until
  • possibily others I can't think of.
With a few minor change these can all be used in any looping construct.
The reason to use one over another is because the chosen loop construct makes the code easier to understand, or the program's logic clearer.
In the context of the given assignment, the most natural choice, in my opinion, would be the for loop. I say this because the problem has a set number of loops and the for statement automagically gives the count needed to display the remaining number of bottles.
With a while loop the index must be created outside the loop and manually changed within the loop.
The only reason I can see to require using a while loop is to make sure the student understands how to use it and to compare the for and while loop structures.

Mark

P.S. If you can make it work with a for loop you've got all the pieces right and all that is left is to figure out the differences needed to make a while loop work.


Mark Henwood
mhenwood@ieee.org

Last edited by chickentree; 03-25-2016 at 09:42 PM.
   
Reply With Quote
Assignment 6
Old
shaolinkidd
Member
 
Status: Offline
Posts: 17
Join Date: Jul 2015
Default Assignment 6 - 08-06-2015, 01:51 PM

https://gyazo.com/a466644d1a0ce42fb1ecbdfa29e16f03
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 08-06-2015, 03:37 PM

Quote:
Originally Posted by shaolinkidd View Post
ndx = 99
while ndx > 0
Do all your singing stuff
ndx=ndx-1
stuff to do after the song has ended.

When you get to 1 it will sing about one bottle of soda and decrement ndx to 0 at which point the while loop will exit
Note: for testing I would make ndx=3 and make sure everything works then change it to 99 before you submit it.

Mark


Mark Henwood
mhenwood@ieee.org
   
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 ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.