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

  • Home
  • SEARCH
  • 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 8177241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:27:36+00:00 2026-06-06T23:27:36+00:00

This code works fine, but I need to simplify it for more clearness and

  • 0

This code works fine, but I need to simplify it for more clearness and hopefully more efficiency:

int i = 0;

if (p.cap()) n++;
if (p.creditcard()) n++;
if (p.email()) n++;
[...]
if (p.price()) n++;
if (p.url()) n++;
if (p.zip()) n++;

if (n == 0) p.standard();

As the code says, I need to call multiple methods (I don’t know the finite number of them). Every p.()* method returns a boolean value, and n is incremented only if the value returned is true. If n==0 (this happens when EVERY method called returns false) then I need to call p.standard().

How can I write a more clear and efficient code? I tried with the or condition, something like this:

if (!( p.cap() || p.email() || p.isbn() || p.number() || p.phone() ||
       p.price() || p.time() || p.url() || p.zip() || p.creditcard()
    )) {
        p.standard();
}

But obviously it didn’t work properly (example: if p.cap() returns true the other methods are not called).

I need to call every method.

  • 1 1 Answer
  • 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. Editorial Team
    Editorial Team
    2026-06-06T23:27:37+00:00Added an answer on June 6, 2026 at 11:27 pm

    You did not specify if every method has to be called, but it seems you want to call them all regardless of individual results. So use the simple or operator: | (not the short
    circuit or ||).

    if (!( p.cap() | p.email() | p.isbn() | p.number() | p.phone() |
       p.price() | p.time() | p.url() | p.zip() | p.creditcard()
        )) {
            p.standard();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please i need help, this code below works fine on my localhost, php5.3+ but
I need some help with virtual attributes. This code works fine but how do
This code works fine, but I'll want to handle exception if any thing goes
This code works fine to find an available room within certain date, but it
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
This loop works fine in Main function but when copy this loop code in
I have this simple code, using Joda-time. Works fine, but I have a problem.
This code works fine in Chrome. However, in Firefox, when it hits the GMxhr
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
The code below is creating a server to communicate with clients.This code works fine

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.