While Loops
What is a while loop? That was my first question when I started coding. After researching, I then clearly understand what a while loop is. It controls a sequence of repetitions. The while structure executes a series of statements continuously while the expression is true. The expression must be updated during the repetitions or the program will never escape out of while. As the site, processing (www.processing .org) says that it can be very dangerous because the code inside the while loop will not finish until the expression inside while becomes true. So in a simpler way to explain a while loop is that it repeats an action until the statement becomes false. Meaning where it can’t repeat the code any more because there isn’t anything to repeat.
While (expression) {
Statement
}
In my project I have used nail polish bottles in order to teach what while loop does through a stop motion video. I have six colors of nail polish bottles continuously painting nails until there is no more nail polish left. The nail polish bottles disappear once a hand has been painted. This is to show that the nail polish bottles have been used and that there is no use keeping it on the screen.
So, while there are nail polish bottles there to paint a hand it will keep repeating nails but if there are no nail polish bottles left to paint nails then this statement turns false. How can the nails keep getting painted if there are no bottles of nail polish left to paint? This is what a while loop is and this is what I have portrayed through my exhibition piece.
While (there are nail polish bottles to paint nails then this will continuously repeat) {but if there are no nail polish bottles to paint nails then no nails can be painted therefore this statement cannot work. It becomes false.
}
No comments:
Post a Comment