+ 1

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

15th Apr 2021, 5:03 PM
JoseD - avatar
6 Answers
+ 4
JoseD No process will go on step by step. After running first for loop 2nd will start.
15th Apr 2021, 5:07 PM
A͢J - avatar
+ 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.
15th Apr 2021, 5:09 PM
CamelBeatsSnake - avatar
+ 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
15th Apr 2021, 9:34 PM
Mirielle - avatar
+ 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.
17th Apr 2021, 1:10 PM
Vamsi Chowdary
Vamsi Chowdary - avatar
+ 1
Can't we use Threading in javascript ??
17th Apr 2021, 11:22 AM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
+ 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.
17th Apr 2021, 11:55 AM
CamelBeatsSnake - avatar