Need help my while loop in my program seems not working

dear sir

I want to write a program for printing “Hello World” & then ask for reprinting in y/n. if answer “c” is

c!= ‘y’ or ‘Y’ or ‘n’ or ‘N’ then it ask Enter the correct decision

‘n’ or ‘N’ then exit from loop

‘y’ or ‘Y’ then again printing “Hello World” & then again repeat

I write my program as given below. in this problem highlighted while loop while((c!='n'||c!='N')||(c!='Y'||c!='y')) is not working properly.

in this loop if I enter c=n or y then this loop is executed rather than get out from the loop which should be wrong. kindly tell me in this while loop where I did a mistake?


#include <stdio.h>

int main()

{

   char c;

   int x[100];

  do{

   printf("hello world\n");

   printf("r u want to continue y/n=");

   scanf(" %c",&c);

if(c=='n'||c=='N')

    break;

   **while((c!='n'||c!='N')||(c!='Y'||c!='y'))**

   {

       printf("\nEnter the correct decission=");

       scanf(" %c",&c);

   }

   if(c=='n'||c=='N')

    break;

    }

   while(c=='Y'||c=='y');

   return 0;

}

to exit from the inner loop (while),
use break inside while loop

	if(c=='n'||c=='N')
	break;
1 Like