The condition is checked once at the start and, if the loop is entered, once after the execution of the body on each iteration. So no, it will not exit immediately, even if k
is altered while the body is being executed.
Oh, and you probably meant k == 7
(recall that ==
compares while =
assigns). Some will even write 7 == k
to avoid potentially making this mistake.
This doesn't really have much to do with threads. For instance, consider:
int k = 7;
while (k == 7) {
k = 8;
System.out.println("here!");
}
here!
Notice how the body is still fully executed even though k
is immediately changed to a value that no longer satisfies the loop condition.