break;
Go to solution
Solved by madknight3,
@alphabeta - Note that replacing break with continue in your original example doesn't do anything useful.
for(int r=0;r<cases;r++){ if(r%2==0 && x[r]%2==0 || r%2==1 && x[r]%2==1 ) { a=false; continue; // this doesn't do anything because if it's getting in the if block, it wont be getting in the else block anyway and you don't execute any other code in the loop } else { a=true; } // If you have extra code here, then continue would ignore it. So you only need it if extra code goes after the else statement that you want to ignore.}
Just wanted to make sure it's clear.
Also, just wanted to mention this.
// these kinds of statementsif (condition) { variable = true;}else { variable = false;}// can be rewritten asvariable = condition// in your case it's the oppositeif (condition) { variable = false;}else { variable = true;}// so you just negate itvariable = !condition// Example using your codefor (int r=0;r<cases;r++){ a = !(r%2==0 && x[r]%2==0 || r%2==1 && x[r]%2==1);}// It works the same so it's best to go with whatever you think is easier to understand.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now