I have code like this:
public void Method() { if(something) { // Some code if(something2) { // Now I should break from ifs and go to the code outside ifs } return; } // The code I want to go if the second if is true }
Is there a possibility to go to that code after ifs without using any go to statement or extracting rest of the code to the other method?
Yes, I know Else ;)
But this code is farly long and should be run IF the first IF is false and when the first IF is true and the second is false. So extracting a method I think is the best idea.
In Python, the break statement provides you with the opportunity to exit out of a loop when an external condition is triggered. You'll put the break statement within the block of code under your loop statement, usually after a conditional if statement.
breaks don't break if statements. But break s don't break out of if s. Instead, the program skipped an entire section of code and introduced a bug that interrupted 70 million phone calls over nine hours. You can't break out of if statement until the if is inside a loop.
To answer your question:
public void Method() { do { if (something) { // some code if (something2) { break; } return; } break; } while( false ); // The code I want to go if the second `if` is true }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With