two "for" loops can be executed at the same time? | Sololearn: Learn to code for FREE!

+1

two "for" loops can be executed at the same time?

4/15/2021 5:03:40 PM

JoseD

6 Answers

New Answer

+4

JoseD No process will go on step by step. After running first for loop 2nd will start.

+4

JoseD You can nest a for loop. Be mindful of nesting too much (too many levels of nesting). It can get complex very fast. When you have a nested loop, the loops aren't executed at the same time, strictly speaking. One level nesting means the internal loop runs for every item in the outer loop.

+3

Even a nested for loop isn't asynchronous, the inner loops get executed then the program goes back to the outer loop and the procedure continues. A closer method to get many loops executed at the same time or asynchronously is to use the setTimeout with the es6 promise

+2

In programming languages, the code excute from step by step. We write code line by line for readability. So, we can write two for loops in a code and it is called as nested for loop. But first for loop executes then goes to second for loop.

+1

Can't we use Threading in javascript ??

+1

🌀 Shail Murtaza شعیل مرتضیٰ No, it's single-threaded in terms of what the user can control, but it's non-blocking thanks to the event loop. In newer versions of node, you can use worker threads to solve some of the problems traditional threading might solve. You have the web worker API in the browser.