#include <stdio.h>
int main()
{
int i=1, j=1;
while (i <= 4 || j <= 3)
{
printf("%d %d\n",i, j);
i++;
j++;
}
return 0;
}
1 1
2 2
3 3
4 4
Press any key to continue . . .
Just like relational operators (<, >, >=, <=, ! =, ==), we can also use logical operators in while loop. The following scenarios are valid :
while(num1<=10 && num2<=10)
-using AND(&&) operator, which means both the conditions should be true.
while(num1<=10||num2<=10)
– OR(||) operator, this loop will run until both conditions return false.
while(num1!=num2 &&num1 <=num2)
– Here we are using two logical operators NOT (!) and AND(&&).
while(num1!=10 ||num2>=num1)
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.