Does that affect the conditionnal process ?
Yes, it does. In the first case, isBored()
is never called nor its result checked if isSleepy()
returns true. In the second case, it is checked, it's completely independent. Similarly, walkRight
and walkLeft
won't be called in the first block if isSleepy()
returns true, but they will be in the second block.
This reformatting of the first code block may help make things more clear;
if(isSleepy()){
sleep(1);
} else {
// The below only happens if isSleepy() returned false
if (isBored()){
dance();
dance();
} else {
// These only happen if isSleepy() returned false AND isBored() returned false
walkRight(50);
walkLeft(50);
if(isHungry()){
eat();
}
}
}