0

I have a very basic question regarding the for loop. When we call a method (return or void) on some element inside the for each loop, does the loop waits until the method finishes or does it move on to the next element in the collection immediately?

2 Answers 2

2

Unless the method is run in a new thread, the next iteration of the loop will not start until the previous one is completed

That you are asking this question indicates to me that you may not fully understand the concept of the Thread stack (vs the global Heap). I'm not trying to be mean but understanding how the thread stack works is very important

Sign up to request clarification or add additional context in comments.

Comments

0

It will run through the method before moving on to the next element.

3 Comments

regardless it's going to finish before moving on. Here is a site that gives you the basics on how for loops work. beginnersbook.com/2015/03/for-loop-in-java-with-example
contrary to belief computers can only do one thing at a time. Here is another site that explains how they 'multitask'. tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/…
@KennyFreeman Even if there are multiple processors? By the way, has the page that you pointed to been updated in the last almost 20 years? Doesn't look like it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.