| | |
C++ break and continue statements
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
hey,
i read that in C++ some programmers consider using break and continue statements as a violation of structured programming practise....... and usually avooid using them except in switch statements..., i will like to know how to use the structured equivalent of these statements.....
i want to know the statement that can replace a break and that that can replace continue statement in a program...
i read that in C++ some programmers consider using break and continue statements as a violation of structured programming practise....... and usually avooid using them except in switch statements..., i will like to know how to use the structured equivalent of these statements.....
i want to know the statement that can replace a break and that that can replace continue statement in a program...
00110101
After setting up your Flow chart make your pseusocode just for anlyzing where/when you should put those syntax.
I dream to exceed to the highest peak.
http://www.ronaldalversado.com
http://www.ronaldalversado.com
>i read that in C++ some programmers consider using break and continue
>statements as a violation of structured programming practise....... and
>usually avoid using them except in switch statements...
That's because they're stupid. It's like the whole single entry single exit crap that structured programming aficionados spew. The result is theoretically "pure", but it's almost always more complicated and the flow of control is harder to follow. That flies in the face of the best advice I can give: write the simplest code you can get away with.
>i want to know the statement that can replace a break and that that can
>replace continue statement in a program...
A break is generally replaced by a status flag in the loop condition:
becomes:
A continue is easy to replace by reversing the continue condition and executing the loop logic on the body:
becomes:
It really depends on both your style and what kind of loop you're writing whether one or the other works better. Most of the time I tend to prefer using break over flags, and I prefer using a reversed condition rather than continue.
>statements as a violation of structured programming practise....... and
>usually avoid using them except in switch statements...
That's because they're stupid. It's like the whole single entry single exit crap that structured programming aficionados spew. The result is theoretically "pure", but it's almost always more complicated and the flow of control is harder to follow. That flies in the face of the best advice I can give: write the simplest code you can get away with.
>i want to know the statement that can replace a break and that that can
>replace continue statement in a program...
A break is generally replaced by a status flag in the loop condition:
while ( something ) { if ( something else ) break; // The rest of the loop }
bool done = false; while ( !done && something ) { if ( something else ) done = true; else { // The rest of the loop } }
while ( something ) { if ( something else ) continue; // The rest of the loop }
while ( something ) { if ( !something else ) { // The rest of the loop } }
New members chased away this month: 3
![]() |
Similar Threads
- Practice problem (C++)
- switch statements (C++)
- Psuedocode (C++)
- Can somebody help me plz? (C++)
- getline() error when cin is redirected (C++)
- I can't figure out how to change my jbutton font and color ( heres the code ) (Java)
Other Threads in the C++ Forum
- Previous Thread: Design Tools Tutorials
- Next Thread: Please help about USER INPUT
| Thread Tools | Search this Thread |
Tag cloud for C++
api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy directshow dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference rpg simple string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






