I have this piece of codeif (!expr1) {    codeblock1;} elseif (expr2) {    codeblock2;    codeblock1;}It is pissing the hell out of me because I am trying to refactor it in such a way that there is no repetitive code, but I keep getting different results.if (!expr1 || expr2) {    if (expr2) {        codeblock2;    }    codeblock1;}What is the logical difference between these two examples?
Combine if blocks with repetitive code
coding;logic
In snippet 1 you are explicitly stating that you don't want codeblock2 to be run if expr1 is false.In snippet 2 you are stating that you DO want codeblock2 to be run, even if expr1 is false, as long as expr2 is true.Also, assuming that codeblock1 and codeblock2 are a series of lines of code (more that just one line), you can extract them to methods. That way you could do:if (!expr1) {    codeblock1(); // calling a method} elseif (expr2) {    codeblock2(); // calling a method    codeblock1(); // calling a method}... which is not cosidered code repetition.