//Instead of writing
text += cars[0] + "<br>";
text += cars[1] + "<br>";
text += cars[2] + "<br>";
for (let i = 0; i < cars.length; i++{
text += cars[i] + "<br>";
}
syntax: for(statement 1; statement 2; statement 3){
//code block to be executed
}
//Statement 1 initializes the variable used in the loop (let i = 0). Many values can be initiated (separated by coma)
//Statement 2 evaluates the condition of the inital value. If it returns true, the loop will start over again, if it returns false, the loop wil end
//Statement 3 increments the value of the inital variable. It can do anything like negative increment (i--), and positive increment (i = i +15)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter