Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Thread Tools Display Modes
Comments on the types of loops
Super Moderator
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Comments on the types of loops - 03-25-2016, 10: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.


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

Last edited by chickentree; 03-25-2016 at 10:42 PM.
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 ©2022, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.