Originally Posted by
sfff
Hi,
i will like to assign multiple conditions for while loop with ||.
however it seems that only the first 2 conditions will be consider and other will be ignore.
So my question is how can i assign many many conditions for while loop with || , like the following does,
while ( guess[0]==guess[1] || guess[0]==guess[2]|| guess[0]==guess[3] || guess [1]==guess [2] || guess[2] == guess[3])
Perhaps guess[0] equals guess[1] or guess[2]?
Note that logical OR will short-circuit in this case. An example, of what I mean:
Code:
zac@neux:code (1) $ gcc ss.c -o ss
zac@neux:code (1) $ ./ss
loops = 14, foo() = 11
zac@neux:code (1) $ cat ss.c
#include <stdio.h>
int foo(void)
{
static int x = 0;
return ++x;
}
int main(void)
{
int x = 0,
loops = 0;
while(x < 5 || foo() < 10)
{
x++;
loops++;
}
/* Don't expect foo() to be called "loops" times */
printf("loops = %d, foo() = %d\n", loops, foo());
return 0;
}
Note that "foo()" wasn't called for every iteration (only once x < 5 became false).