A
aleksa
int* test1 (int* src)
{
int var1, var2;
do {
var1 = *src++;
var2 = *src++;
} while ( (var1 == 1) || (var2 == 2) );
return src;
}
int* test2 (int* src)
{
int var1, var2;
while (1) {
var1 = *src++;
var2 = *src++;
if ( (var1 == 1) && (var2 == 2) ) break;
};
return src;
}
test1 and test2 work the same.
They read var1 and var2 from src++ and return src
when both var1==1 *and* var2==2.
So, why does while loop need || instead of && ?
Can this negative logic also happen anywhere else?
Thanks,
Aleksandar
{
int var1, var2;
do {
var1 = *src++;
var2 = *src++;
} while ( (var1 == 1) || (var2 == 2) );
return src;
}
int* test2 (int* src)
{
int var1, var2;
while (1) {
var1 = *src++;
var2 = *src++;
if ( (var1 == 1) && (var2 == 2) ) break;
};
return src;
}
test1 and test2 work the same.
They read var1 and var2 from src++ and return src
when both var1==1 *and* var2==2.
So, why does while loop need || instead of && ?
Can this negative logic also happen anywhere else?
Thanks,
Aleksandar