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 8102233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:11:31+00:00 2026-06-05T23:11:31+00:00

I usually use a boolean ‘firstTime’ like this: in C++: bool firsTime = true;

  • 0

I usually use a boolean ‘firstTime’ like this:

in C++:

bool firsTime = true;
for (int i = 0; i < v.size(); i++) {
    if (firstTime) {
        //do something just once
        firstTime = false;
    }
    else {
        //do the usual thing
    }
}

in java it would be the same using a boolean instead a bool so I don’t put the code.

The questin is, is there anyway in java or c/c++ to use a bool/boolean in an if clause and automatically assign to that bool/boolean the value false?

I know it seems a nonsense but it would save my code A LOT of lines because I’ve a lot of base cases and in big fors or whiles that is critical.

I do want to know if there is anyway to put a value to false after using it in an if clause. I know that in a for or while we can just use:

if (i == 0)

But I was also thinking in calls to functions that needs to know things and that usually is referenced by bools.

  • 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-05T23:11:32+00:00Added an answer on June 5, 2026 at 11:11 pm

    If you don’t have a count already, you can use one instead of a boolean

    long counter = 0;
    for(String arg: args) {
        if(counter++ == 0) {
           // first
        }
    }
    

    An alternative which uses a boolean is

    boolean first = true;
    for(String arg: args) {
        if(first && !(first = false)) {
           // first
        }
    }
    

    For sets there is a similar pattern

    Set<String> seen = ...
    for(String arg: args) {
        if(seen.add(arg)) {
           // first time for this value of arg as its only added once.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use like this $ find -name testname.c ./dir1/dir2/testname.c $ vi ./dir1/dir2/testname.c it's
I usually use expressions like this CommandArgument='<%# Container.DataItemIndex.ToString() %> ' But I could not
I usually use code like this: using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings[MyConn].ConnectionString)) { var
I usually use linux for mysql and have something called mysqltuner.pl and this is
I usually use something like my $dir=/path/to/dir; opendir(DIR, $dir) or die can't open $dir:
I usually use code like this: dispatch_queue_t queue = dispatch_queue_create(queue_name, NULL); dispatch_async(queue, ^{ //Code
I usually use this line to import file from out of the current folder
I usually use JSON with jQuery to just return a string with html. However,
I usually use ax.set_rasterized(True) to rasterize the figure so that it could handle transparency
I usually use sql parameters with queries, but in this case I need to

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.