Mushfiq Mammadov wrote:
No you're not. A single equals (=) is an assignment. Double equals (==) is an equality check.Mushfiq Mammadov wrote:In first loop we check the value of variable b.
Tim Driven Development | Test until the fear goes away
Tim Cooke wrote:
Mushfiq Mammadov wrote:
No you're not. A single equals (=) is an assignment. Double equals (==) is an equality check.Mushfiq Mammadov wrote:In first loop we check the value of variable b.
Roel De Nijs wrote:Let's start with a very, very, very important rule: The compiler doesn't execute any code! So every compiler error you get, is because the compiler knows something is wrong without executing any line of code.
Roel De Nijs wrote: For the 1st loop, the assignment is done in the while loop, so that line should be executed before the compiler would know it's always true. In the 2nd loop, the compiler knows without executing any code that will run forever and the statement after the while loop will be unreachable.
Roel De Nijs wrote:Here is another topic about unreachable code with some examples.
Roel De Nijs wrote:And here is another one with try-catch-finally blocks
If you would comment the finally block, 4 is still unreachable because of 3.
Mushfiq Mammadov wrote:The problem is that sometimes I can’t determine which code is known without executing or which code with executing by compiler.
Mushfiq Mammadov wrote:In above examples confuse me and I think that compiler know the value of b ( while(b=true) ) is always true (according assignment) without executing.
Mushfiq Mammadov wrote:System.out.println("after loop");[/tt] isn’t unreachable according break. But break is also unreachable although does compile.
Mushfiq Mammadov wrote:At first I don’t understand it, then I think that maybe you want to say because of 2. Do I think your intention correct or not?
Roel De Nijs wrote:Does compile time constant sound familiar? If you have a compile time constant, the compiler knows the value; otherwise it knows nothing at all
Roel De Nijs wrote:and I gave you credits for reporting
Do you pee on your compost? Does this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|