#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 understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.