KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In C, C++ and C# when using a condition inside a function or loop statement it's possible to use a continue or return statement as early as possible and get rid of the else branch of an if-else statement. For example: while( loopCondition ) { if( innerCondition ) { //do some stuff } else { //do other stuff } } becomes while( loopCondition ) { if( innerCondition ) { //do some stuff continue; } //do other stuff } and void function() { if( condition ) { //do some stuff } else { //do other stuff } } becomes void function() { if( condition ) { //do some stuff return; } //do other stuff } The "after" variant may be more readable if the if-else branches are long because this alteration eliminates indenting for the else branch. Is such using of return/continue a good idea? Are there any possible maintenance or readability problems?
Tags (comma-separated)
Save Edits
Cancel