Hi dear welcome to "CodePrime" Blog . In this post You are going to learn Loop uses in javascript | While, do while, for loop | what is loop? | JS Tutorial | By CP. First Creat A index.html file Copy This HTML CODE and pest it one your code editor. 2ndly creat loop.js file Then Copy The JS CODE and pest it then open the index.html file with your browser.
HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/js/loop.js"></script>
<title>javascript</title>
</head>
<body>
<h2>Javascript Tutorial</h2>
<h3>By Codeprime</h3>
</body>
</html>
JAVASCRIPT CODE
let i=0; //UNIVERSAL VARIABLE
//while example
while(i<5) {
console.log("The Number is" +i);
i++;
};
//do-while example
do{
console.log("The Number is" +i);
i++;
}
while(i>5);
//for loop example
for( i=0;i<5;i++) {
console.log("the number is " +i)
}
//repeating loop
for( i=0;i<100;i++) {
console.log(i+ "Code prime");
}
0 Comments