Alice Community

Alice Community (
-   Questions and Comments (
-   -   Assignment 6 - Loops (

chickentree 03-25-2016 10:38 PM

Comments on the types of loops
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:[LIST][*]for[*]while[*]do ...while[*]repeat ... until[*]possibily others I can't think of.[/LIST]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.

All times are GMT -5. The time now is 06:23 AM.

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