Different criteria for some 'unreachable code'?

I'm trying to understand why in some situations the compiler seems to check if certain code is unreachable or not.
From the below 2 examples the compiler will detect unreachable code in different lines depending of the loop condition:

But this is not the case if we have a conditional statement? Why the compiler does not detect that there is still unreachable code also in both examples?

I know this has been asked before on this forum. I think the If-block gets 'preferential treatment'. For years, a common idiom in many languages has been this:

Then, when you want to debug, you change one value in one spot.

With things like log4j, this is really sort of obsolete, but you don't want to change the compiler in a way that can break existing code, nor do you want to annoy 'old school' programmers who have been doing exactly this sort of thing for possibly decades.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

David Sabate wrote: I'm trying to understand why in some situations the compiler seems to check if certain code is unreachable or not.

But this is not the case if we have a conditional statement? Why the compiler does not detect that there is still unreachable code also in both examples?

Interestingly, the compiler does detect the unreachable code for the condition statement. It is just designed to not complain about it....

Why? There is a use-case where unreachable code is actually important. For example, what if you wanted to do this?

basically, you like to do stuff during testing, but once it is all tested, you want to set a flag and all debugging stuff is turned off. The unreachable code checks would have required you to go back and comment out the code.

So, to allow this use-case, the Java language is designed to ignore unreachable code for condition statements.