Loops are very important to use in Javascript. Loops are used to repeat a block of code. It makes it easier to loop the code instead of writing the same code over and over again. Its repeats the block of code until a condition causes it to end. Its important because performs tasks quickly. The “For” Loop is used when we want the code to run a specific number of times. The syntax for the “for” loop is for (int i=start_value; i < finish_value; i = i + by_count ){ do something}(utah.edu). There are three parts of a for loop. They are the keyword [for] that begins the loop, the condition that is being tested, and the keyword [for] that ends the loop (freedomscience.com). When we don’t have a specific number of times for the code to run, the while loop will be used. The code will run until a condition is met. The syntax for the while loop is while ( condition is true ) do something % Note: the “something” should eventually result % in the condition being false end. (utah.edu)
9.7 Looping. Freedom Scientific. (n.d.). Retrieved March 2, 2023, from https://support.freedomscientific.com/Content/Documents/Other/ScriptManual/09-7_Looping.htm#:~:text=Similar%20to%20a%20While%20loop,keyword%20that%20terminates%20the%20loop.
Germain, H. J. de S. (n.d.). For loop. Programming – For Loop. Retrieved March 2, 2023, from https://users.cs.utah.edu/~germain/PPS/Topics/for_loops.html
Germain, H. J. de S. (n.d.). The “while” loop. Programming – While Loop. Retrieved March 2, 2023, from https://users.cs.utah.edu/~germain/PPS/Topics/while_loops.html
Leave a Reply
You must be logged in to post a comment.