Demonstrate nested loops with return statements in JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

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
raja
Published on 07-Sep-2020 08:57:37
Advertisements