Using a for loop
In this blog, I will discuss the various uses of loops. Loops can be used to repeat a block of code by repeating until a certian condition is true or false. This can be very useful for printing numbers in order, printing/editing arrays, and the list goes on and on.
There are two types of loops; the for loop and the while loop. The for loop is declared with the syntax of "for(start variable; condition; iterator)". The way it works is the start variable is declared to determine what the starting value of the variable will be. Next, the condition will be set to allow the loop to run as long as the variable is true, and an iteration statement will edit the start variable. Here is an example of a for loop below:
The while loop is declared first by using a pre declared variable outside of the element, but then using while(condition), you can then add a block of code that you wish to be looped as long as the condition is true. It is most common to see a variable created specifically for the while loop on the line directly before the loop is declared. Here is an example of a while loop below: