When we want to execute a piece of code for a number of times, without writing it multiple times, then we use loops for that.
For example, If you want to print “Hello World” 5 times, then you can write something like this.
Console.log("Hello World")
Console.log("Hello World")
Console.log("Hello World")
Console.log("Hello World")
Console.log("Hello World")
But this is not an effiecient way to write it, and if the number increases from 5 to 100 or even 1000, then writing it 1000 times doesn’t make sense, and therfore Loops are very useful in these types of Scenarios.
Let’s take 1 more example, where we have to print numbers from 1 to 5, then again we can write something like this.
Console.log(1)
Console.log(2)
Console.log(3)
Console.log(4)
Console.log(5)
Again this is not an effiecient way to write it, and if the number increases from 5 to 100 or even 1000, then writing it 1000 times doesn’t make sense, and therfore Loops are very useful in these types of Scenarios.
Now, Let’s see,
How can we write the code for printing “Hello World” multiple times using Loops
How can we write the code for printing numbers 1 to 5 using Loops This article offers free shipping on qualified Face mask products, or buy online and pick up in store today at Medical Department
for(let i=1;i<=5;i++) {
Console.log("Hello World")
}
for(let i=1;i<=5;i++) {
Console.log(i)
}
let i=1;
while(i<5) {
Console.log("Hello World")
i++
}
let i=1;
while(i<5) {
Console.log(i)
i++
}
let i=1;
do {
Console.log("Hello World")
i++
} while(i<5)
let i=1;
do {
Console.log(i)
i++
} while(i<5)
for(Variable Initialization;Condition;Increament) {
Block of Code
}
while(Condition) {
Block of Code
}
do {
Block of Code
} while(Condition)
We have covered below topics in this session
Heyecan Verici Kazanclar icin Gates-of-Olympus Slot
Difference between Functions and Methods in Javascript Before discussing the difference between a function and…
In JavaScript, an object is a data structure that allows you to store collections of…
Objects, Classes and Constructor in Javascript Classes and Objects A class in any programming language…
We will start from object oriented programming basics like What are different concepts in Object…
Why we can not over ride a Constructor This is a very important question, that,…