Friday, December 16, 2016

Lab 8: Loops

https://thimbleprojects.org/jh19tommy2/155092/Lab8.html

      This is lab 8, where we demonstrate our understanding of the four types of loops. That includes the For loop, the For/In loop, the While loop, and the Do/While Loop. Loops are extreme useful when you want to execute the same block of code multiple times in different, but similar conditions. It can help you write less amount of codes, which is less work for the programmer, and it's easier for the computer to read, which is less work for the computer, therefore it takes less time to process. The For loop is the most common used loop of all, where you have three statements to execute the code under a certain condition. The For/In loop is similar to the For loop, but used for properties instead. The While loop continues the loop as long as the condition is true. In the Do/While loop,The code in "do" will execute when the condition in "while" is true. But it will at least execute once even if the condition is false.

      Inside my lab, I have a table with 4 cells, each created to contain each of the loops needed to be demonstrated. In the For loop demonstration, I used a For loop to list my array called "food", and made it execute, starting at 0, until all the index in the "food" array is listed. In the For/In loop, I listed all the properties inside my array called "subject", which loops through all the properties with only using one statement. In the While loop section, I first wrote all the variables, then I set up the While loop to run as long as a variable is less than the length of my array, which listed what I like to do in my free time. In the last but not least, the Do/While loop, I put all variable before the loop, then used Do, to execute a block of code, then used While to made the loop stop the Do after a certain condition.

No comments:

Post a Comment