using if +break, new post

Thanks in advance, and sorry for post it again just to make it clear for the us

but I need to do the same code in both if statement guys, and I need the priority for 1st if and then 2nd if

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

if(condition1 && condition2){
action

}

else if((condition1) && opposite(condition2)){
action (the same above)

}
}// end for


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

if(x==b)&& (x==c)){

f=x;
break;//does not work
}

else if (x==b)&& (x!=c)){
f=x;
}

}// end for
Last edited on
closed account (3hM2Nwbp)
By opposite(condition2) do you mean !condition2 ?

If that's the case, then condition 2 doesn't matter.

1
2
3
4
5
6
7
if(condition1 && condition2 || condition1 && !condition2)

// is equivalent to 

if(condition1)

// so long as neither expression modifies anything 


1
2
3
4
5
6
7
8
for(int i = 0; i < counter; ++i)
{
  if(myarray[i] == b)
  {
    f = x;
    //break; will exit the loop if desired
  }
}
Last edited on
exactly !condition2
but how do u fit the for loop and if together bcz I could not understand u plz
Topic archived. No new replies allowed.