Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 165253

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:53:18+00:00 2026-05-11T11:53:18+00:00

#include<iostream> using namespace std; int main() { char again; do { cout<<you are in

  • 0
#include<iostream> using namespace std;  int main() {      char again;     do     {         cout<<'you are in the while loop';         cout<<'do you want to continue looping?';         cin>>again;     } while (again != 'n' || again != 'N');      system('pause');     return 0; } 

i know something is wrong with the test condition in the ‘while’. But I can’t figure it out.

when the input of the user is neither ‘n’ nor ‘N’, the loop should keep on printing the code ‘you are in the while loop’. Once ‘n’ or ‘N’ is pressed, the program will be terminated.

However for my code, program will keep on looping the code regardless what character i enter. But when i change the ‘||’ to ‘&&’, the program can ran as desired. Anyone can tell me what is going on?

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:53:19+00:00Added an answer on May 11, 2026 at 11:53 am

    This is a common boolean logic question. || means ‘or,’ which means ‘as long as one side of this is true, then the expression is true.’ So when you pass an uppercase 'N' to c != 'n' || c != 'N' the program says ‘well, 'N' is not equal to 'n', therefore one side of the expression is true, therefore the whole expression is true and there is no need to check the rest of the expression.’ Even when you press lowercase 'n', the program says ‘well, 'n' is equal to 'n', but it’s not equal to 'N', therefore one side of the expression is true, therefore the whole expression is true.’ This is what is happening in your while loop.

    On the other hand, && means ‘and’ which means ‘both sides of the expression must be true’; when you pass an uppercase 'N' to c != 'n' && c != 'N' the program thinks ‘'N' is not equal to 'n', but it is equal to 'N', therefore only one side of the expression is true, therefore the expression is false.’

    This gets confusing because if you were testing to see if the characters entered were equal to particular values you would use || (e.g., ‘I want to know if 'a' or 'b' or 'c' was entered’).

    Basically, when you would use || for a particular expression, and you want the opposite of that expression then you need to change to && (e.g., I want none of 'a', 'b' or 'c'; or to put it another way, the value cannot be 'a' and it cannot be 'b', and it cannot be 'c'‘). Likewise, if you would use && for a particular expression, and you want the opposite of that expression then you need to use ||. This is one of De Morgan’s laws, which I would recommend you read up on so you can avoid having to rediscover each of them on your own.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Every operating system is going to do this in a… May 12, 2026 at 12:35 am
  • Editorial Team
    Editorial Team added an answer If you do not wish or need to fully log… May 12, 2026 at 12:35 am
  • Editorial Team
    Editorial Team added an answer It looks like the bug you're having was merged into… May 12, 2026 at 12:35 am

Related Questions

I’ve got the following code: #include <iostream> using namespace std; int main() { char*
I have this program in c++: #include <iostream> using namespace std; int main() {
#include <iostream> using namespace std; class Marks { public: char* name(); }; char* Marks::name()
Well, not random, because its the same every time, but #include<iostream> using namespace std;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.