[HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

[HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Post by flex567 »

In this section there is a sentence that is not completely clear
In case of a for loop, and the control executes the updation section before moving on to the next iteration.
Can you explain what was meant with this sentence?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Post by admin »

It makes sense when read in continuation of the previous sentence:
In other words, when a loop encounters the continue statement, the rest of the statements in the loop are skipped and the control moves on to execute the next iteration (depending on the loop condition). In case of a for loop, and the control executes the updation section before moving on to the next iteration.
The word "and" is a typo. Should be removed.
So, if you have something like:

Code: Select all

for(int i=0; i<5; i++){
  if(i==2) continue; 
  System.out.println(i); 
}
When i is 2, continue statement will be executed. The print statement will be skipped. But before next iteration is started, the updation section of the for loop i.e. i++ will be executed. So, in the next iteration i will be 3.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Post by flex567 »

In the case above after the continue execution goes to 'i++' and after that it goes to checking condition?
Last edited by flex567 on Sat Oct 06, 2018 8:35 am, edited 1 time in total.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: [HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Post by admin »

yes.
1. updation (in case of for),
2. condition check.
3. if condition is true, loop statements.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

Re: [HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]

Post by flex567 »

Aha, thank you for clarification

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests