Do…while loop keeps looping even when condition is not met [closed]

change

while ((action != 1) || (action != 2) || (action != 3) || (action != 4)); // (1)

to

while ((action != 1) && (action != 2) && (action != 3) && (action != 4)); // (2)

Analysis:

if action == 1

(1) will evaluate to

while(false || true || true || true)

=>

while (true)

(2) will evaluate to

while(false && true && true && true)

=>

while (false)

Leave a Comment