say have following c statement:
if( cond) if( cond) stat else stat
where 'else stat' part of inner if statement according language semantics. need in order make 'else stat' part of outer if statement? knowledge, adding {}
after , @ end of if statement separate them work. correct? there way of doing this?
in case should use compound statement
if( cond1 ) { if ( cond2 ) stat; } else { stat; }
another approach point of view of c syntax less readable , should not used following
if( cond1 ) if ( cond2 ) stat; else ; // empty statement else stat;
however such approach can used internal if contains else if. example
if( cond1 ) if ( cond2 ) stat; else if ( cond3 ) stat; else ; // empty statement else stat;
or can made more readable following way
if( cond1 ) if ( cond2 ) { stat; } else { ; // empty statement } else stat;
Comments
Post a Comment