First, none of the variables are initialised. When reaching line 9 for the first time, what will happen - will the loop execute or will it end? There's no way to tell, since the contents of the variables are unknown (garbage).
As for the loop condition itself, it uses the logical OR operator
||
to combine two conditions.
Let's look at an example:
1 2 3 4 5
|
food people (food!=0) (people!=0) ((food!=0) || (people!=0))
5 5 true true true
5 0 true false true
0 5 false true true
0 0 false false false
|
The only case where the whole condition is false is where
both of the conditions are false.
But if the operator
||
is changed to
&&
, things are different. The condition as a whole is true only when both the conditions are true. That means the condition as a whole is false when
either of the conditions are false.
1 2 3 4 5
|
food people (food!=0) (people!=0) ((food!=0) && (people!=0))
5 5 true true true
5 0 true false false
0 5 false true false
0 0 false false false
|
The remaining question is the required outcome. Is the line
days++;
supposed to be executed when either/both the values are zero? Or not?