0

continue

When would it be a good time to use this in a program?

4th Jul 2017, 12:11 AM
Leroy Dingle
Leroy Dingle - avatar
2 Answers
+ 2
When you do not want to do the rest of the loop before doing the entire loop another time For example : int a[5]={1,2,2,4,4}; int sum=0; foreach(int i in a){ if(i%2){ continue; } sum+=i; } Sum will have the value 12 at the end as this loop sum all even numbers in a. For me, continue should be avoided but it is only personal.
4th Jul 2017, 12:26 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 2
4th Jul 2017, 1:38 AM
Nanda Balakrishnan