Pre-requisite: Assume all 3 processes have same implementation of code except flag variable indices changes accordingly for Pj and Pk and turn is shared variable among 3 process.
The condition:
while flag [j] or flag[k] do
ensures mutual exclusion as no process can enter critical section until flag of other processes is false.
-----------------------------------------------------------------------
Consider the case: turn = k
Pj wants to enter the critical section. It enters the critical section easily as
flag [k] or flag[i]
will be false and the loop will break.
Now, while Pj is executing in its critical section Pi arrives. For Pi :
flag [j] or flag[k]
will be true and it will enter the while loop. Since, turn = k, Pi will execute the loop:
while turn != i do skip;
Now, even if Pj finishes executing it's critical section, it will execute:
if turn = j then turn := k;
which is false and thus the turn will remain k making Pi to execute an infinite loop until Pk arrives which can update turn = i.
So if Pk never arrives Pi will be waiting indefinitely.