[CSI] Question about Continue with Iterative Constructs
Mikhail Nesterenko
mikhail at cs.kent.edu
Mon Feb 21 17:11:33 EST 2022
>
> I had a question about the using continue with iterative
> constructs. in the example from the slides:
>
> int sum=0;
> for (int i = 0; i < 20; ++i) {
> int intVar; cin >> intVar;
> if(intVar < 0)
> continue;
> sum +=i;
> }
>
> The slides say that once continue is reached, we skip the remaining
> statements, and start a new iteration. Does this mean that if a negative
> integer was entered for intVar, we would skip the increment sum statement
> and begin a new iteration in which we will only increment sum with the
> input of a positive integer for intVar?
That is correct. continue, in this case, skips
sum +=i; // it is not an increment, it is a compound addition
And proceeds with the next iteration, considering the next input.
Thanks,
--
Mikhail
More information about the cs13001
mailing list