![]() In this exercise, you must write a for loop that iterates on the myArray variable and prints out all of its members. There are different ways to loop over arrays in JavaScript, but it can be difficult choosing the right one. ![]() For example, if we would want to print only odd numbers using a for statement, we can do the following: for (var i = 0 i < 100 i++) The for loop is used to execute a block of code for a certain number of. The continue statement skips the rest of the loop and jumps back to the beginning of the loop. The for loop repeats a block of code since a specified condition evaluates to false. For example, we can create a loop that loops forever using while(true) and use the break statement to break inside the loop instead by checking that a certain condition was met. The break statement allows to stop the execution of a loop. Let's see an example: var i Ĭonsole.log(i + " bottles of beer on the wall") It is mainly used for iterating over arrays or objects. JavaScript has two methods for running the same code several times.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |