Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Demonstrate nested loops with return statements in JavaScript?
Here’s an example with two loops, outer and inner −
Example
let demoForLoop = ()=>{
for(var outer=1;outer<100;outer++){
for(var inner=1;inner<=5;inner++){
if(outer==3){
return 'THE OUTER VALUE IS EQUAL TO 3 INSIDE THE LOOP';
}
}
}
return 'OUT OF THE LOOP';
}
console.log(demoForLoop());
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo105.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo105.js THE OUTER VALUE IS EQUAL TO 3 INSIDE THE LOOP
Advertisements
