My while loop is not stopping even when the condition is meet. please help

Here is the code for the same .
When I give a=11 and b=44 .then wile loop for a must stop at 20 as 20%10==0 but its not stopping.

int a,b;
cin>>a>>b;
int total=0;

    while((a%10!=0)||(a!=b))
    {   cout<<"a is "<<a%10<<"\n";
        if((a%10==2)||(a%10==3)||(a%10==9))
        total+=1;
        a++;
    }

the while condition becomes true at a = 20 because 20%10==0 but a!=b condition becomes true.so it will execute the loop at a = 20.this is a infinte loop because if a reaches 44 then also a%10!=0 becomes true.there is no ending condition for this loop.

2 Likes

Ok got it my while condition is badly written thanks.

Use && in place of ||

1 Like

Yes , thanks a lot !