break!

Hi guys I want ur help in this plz, I want when the first if gives true, do the statements and break(do not go the else if).

and if the 1st if gives false go and check else if
Please how can I do that ??

for(int i=0; i<counter; i++){//counter value comes from outside this function

if(condition1 && condition2 && condition3){
......
.break;// does not work ??
}

else if(condition1 && condition2 && opposite(condition3)){
.....
.... }
}// end for
Last edited on
That functionality is already inherent in the semantics of if {..} else if {...}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if(someCondition)
{
     //this gets executed if someCondition is true.
     //the else if {} and the else {} do not get executed
}
else if(anotherCondition)
{
     //this gets executed if someCondition is false
     //and if anotherCondition is true. The else {}
     //does not get executed
}
else
{
     //this gets executed if both someCondition and
     //anotherCondtion are false
}


break; actually causes execution to jump out of the loop entirely.
Last edited on
Thanks shacktar, but there is for loop and what i need when the 1st if run do not go to the looop again

http://www.cplusplus.com/forum/general/49420/
Topic archived. No new replies allowed.