There was a exercise in my book, which asked me to write a for loop equivalent to :
for(i=0;(i<4) && (i<5);i++)
but without using && and || operator.
I came up with a solution like this :
for (i=0;;i++)
if((i<4))
if((i<5))
printf("Works!!!\n");
else
break;
else
break;
It works. Since I’m a beginner in C, I want to know whether there are any better solution than this.
Thanks in advance.
Your
&&is combining two conditions such that one is a logically weaker one with respect to the other. If an integer is less than 4 it is necessarily less than 5. Thus(i<4) && (i<5)can just be replaced with(i<4).