in a usefull way? I dont see any useful charge to the continue command. You guys got a useful code with Continue?
In other words, why to use continue?
in a usefull way? I dont see any useful charge to the continue command. You guys got a useful code with Continue?
In other words, why to use continue?
In my opinion, it is usually better to avoid such statements like continue or goto. Avoiding these statements leads in general to more structured code and forces you to design a structured algorithm without statements which make the program jump through the code.
So, no, I don't see a usefull way to use continue.
I wont use continue and goto
Is continue really that bad? I've never really used it, but I can't see how it can screw things up like goto can.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
You can eliminate any continue-using an if
You can use continue to write clever code!!
Mr. C: Author and Instructor
Using continue is not bad. Goto is bad! Continue doesn't screw with the general flow of the program like a goto does.
I didn't saw any *real* good example for continue..
it's not a bad thing, right. but not so usefull too right?
>>it's not a bad thing, right.
Right, it's not a bad thing.
>>but not so usefull too right?
Wrong, all valid statements are useful in their rightful places. Here's an example that reads input from a FILE* processing only the lines that don't start with a # (comment marker in some shells): (same layout as vVv's)
Code:while (fgets(buf, sizeof(buf), fp) != NULL) { if (buf[0] == '#') continue; /* now go process the line */ ... ... }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Here is an example I use to show my students: from C How to Program
continue- used to alter flow of control
Result : 1 2 3 4 6 7 8 9 10Code:#include <stdio.h> int main() { int x; for (x = 1; x <= 10; x++) { if (x == 5) continue; printf("%d ", x); } printf("Used continue to skip printing the value 5\n"); return 0; }
Used continue to skip printing the value 5
Mr. C: Author and Instructor
refer to the structure / flowchart, is there any "CONTINUE" in the program?? i dont think that continue should be good in program structure. just one statements .. goto, continue, break (except for switch usage) is not recommended in program. this is BAD program. try to avoid using the continue anyway.Originally posted by Magos
Is continue really that bad? I've never really used it, but I can't see how it can screw things up like goto can.
-- beely
continue and break don't mess with the flow of the program in the way that goto does. goto is naughty, but continue and break are still your friends. If anything, switch statements are more "bad practice" than break. While continue statements can often times be avoided (though often times they shouldn't be because it often times makes "more logical sense" to use a continue depending on what you'd want to accomplish), break often times can't be avoided (unless you use return) because many times you need to break out of a loop after part of the body has been executed for that particular iteration.Originally posted by beely
.. goto, continue, break (except for switch usage) is not recommended in program. this is BAD program. try to avoid using the continue anyway.
Along with what Polymorphic OOP is saying, break is often time under used. For example lets look at a for loop that scans an array for a value:
Without the break statement the whole array would continue to look for the target_value even after it found it. Continue can also add a level of optimization analogous to this. Even goto's have their place (that doesn't mean I embrace them).Code:int i, contains_value = 0; for(i = 0; i < sizeof(array); i++) if(array[i] == target_value) { contains_value = 1; break; }
according to your code. it's bad programming althoug it's working. why not try this ??Code:int i, contains_value = 0; for(i = 0; i < sizeof(array); i++) if(array[i] == target_value) { contains_value = 1; break; }
so, decide whether which program is better. for me , i would choose my code. as i said, break OR continue in the for-statement is bad structure. have you seen break or continue in flowchart??? no .. is it??? then why should put for break & continue.Code:int i, contains_value = 0; int error = 0; for(i = 0; i < sizeof(array) && error == 0 ; i++) if(array[i] == target_value) { contains_value = 1; error = 1; } --i; // replace back to the value if you wish.
well.... just for comment. switch may use it at anytime. it's not bad practice, and the usage of switch is better than using nested if-statement. switch-statement could found in the flowchart, and it's consider a good structure too!Originally posted by Polymorphic OOP
..., switch statements are more "bad practice" than break. While continue statements can often times be avoided (though often .....