- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- What is the best way to break from nested loops in JavaScript?
- How to use nested loops in Python?
- Reverse array with for loops JavaScript
- Display a two-dimensional array with two different nested loops in matrix form PHP?
- For Loops in Javascript
- How to get sequence number in loops with JavaScript?
- Loops and Control Statements (continue, break and pass) in Python
- Nested collection filter with JavaScript
- Finding closed loops in a number - JavaScript
- Accessing nested JavaScript objects with string key
- Write the syntax of javascript with a code to demonstrate it?
- How do we use nested switch statements in C#?
- How do we use nested if statements in C#?
- Array flattening using loops and recursion in JavaScript
- Write a C program to work on statements using functions and loops

Advertisements