What is a loop or looping?
Looping is a technique in computer programming, through which a certain block of code can be executed(or looped) a number of times.
Programmer can :-
Method 1- Specify the exact number of times a loop should be executed
Method 2- Instruct the computer to keep executing the block of code over and over again (i.e. loop) till a certain condition is being met (i.e is TRUE). As soon as the condition gets False, the looping is stopped. JavaScript looping generally uses this method.
Method 2- Instruct the computer to keep executing the block of code over and over again (i.e. loop) till a certain condition is being met (i.e is TRUE). As soon as the condition gets False, the looping is stopped. JavaScript looping generally uses this method.
Uses of Loops
What is the need of loops? why do we need to repeat blocks of code? Loops are frequently used in the programming world. Specially when working with arrays(advance topic). The exact same code is not executed a no. of times, often one variable's value changes on each execution which is refered to as the counter variable. Like on one loop, its value is 1, on the next it is incremented by 1 and beomces 2, 3 on next and so on.
Throughout this course we will use practical examples to dispaly how and where loops are necessary. In the next lesson on For Loops, we will start with a simple example of creating mathematical tables using loops.
Loop Commands used in JavaScript
- JavaScript For Loop
- JavaScript While Loop
- JS For each Loop
- JS Break Loop
No comments:
Post a Comment
Thank you for your valuable comment