Can you explain what was meant with this sentence?In case of a for loop, and the control executes the updation section before moving on to the next iteration.
[HD Pg 0, Sec. 7.6.2 - terminating-an-iteration-of-a-loop-using-continue]
Moderator: admin
-
- 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]
In this section there is a sentence that is not completely clear
-
- Site Admin
- Posts: 10065
- 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]
It makes sense when read in continuation of the previous sentence:
So, if you have something like:
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.
The word "and" is a typo. Should be removed.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,andthe control executes the updation section before moving on to the next iteration.
So, if you have something like:
Code: Select all
for(int i=0; i<5; i++){
if(i==2) continue;
System.out.println(i);
}
If you like our products and services, please help us by posting your review here.
-
- 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]
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.
-
- Site Admin
- Posts: 10065
- 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]
yes.
1. updation (in case of for),
2. condition check.
3. if condition is true, loop statements.
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.
-
- 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]
Aha, thank you for clarification
Who is online
Users browsing this forum: Bing [Bot] and 119 guests