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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:58:44+00:00 2026-06-09T05:58:44+00:00

I need the opinion of stack overflow to settle something that has been sitting

  • 0

I need the opinion of stack overflow to settle something that has been sitting in the back of my head about for loop efficiency. Now, when I began programming, “getting it to work” was a big priority and most of my for loops looked like this.

for (int i = 0; i < N; i++) {;}

Then I was tought, especially with C++ development that pre-increment saves you some calls, and considering that would be N calls and it doesn’t alter the readability I got into the habit of.

for (int i = 0; i < N; ++i) {;}

This was good enough for a while, but focusing on the readability, and after reading some of Code Complete by Steve McConnell, I arrived at this.

for (int loop_index = 0; loop_index < loop_count; ++loop_index) {;}

And these variables change based on the context of the code. Then I read some of Effective C++ about built in types constructors and assignment. And basically that the difference between

int i = 42;

and

int i(42); 

Is that the former one calls the constructor and the assignment operator while the latter only the constructor. So I got that into my routine whilst coding. So my question, is this the most efficient and readable way of writing a for loop:

for (int loop_index(0); loop_index < loop_counter; ++loop_index) {;}
  • 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-09T05:58:45+00:00Added an answer on June 9, 2026 at 5:58 am

    Actually,

    for (int i = 0; i < N; i++) {;}
    

    is fine. i is an int, so the compiler will optimise the post-increment away anyway. Whether you initialise an int with int i(42); or with int i = 42; is also a question of taste.

    I would also call the iterator i, instead of loop_index. The former is ubiquitously understood, while the latter is strange.

    If you are dealing with iterators, however, the picture changes. Chances are it++ will still be optimised to ++it, but here, I’d rather use pre-increment.

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

Sidebar

Related Questions

I need an opinion and advise from experienced ASP.NET people, what way to go.
Please your opinion on the following code. I need to calculate the diff in
I'm looking for opinion on using Canvas vs. Grid panels in WPF. I need
I need an opinion on writing a managed (C#) wrapper for an unmanaged C++
I’m just working on this interesting thing with ADO.net entities and need your opinion.
I need to pass in a string that gets evaluated at runtime. So I
I need some help with prototypes that are within prototypes. Symfony is very clever
I am new to Java and I need your opinion on the best way
I current use prototype library to handle ajax requests. I have been on stack
I need your opinion. I'm currently working on a web application, based on struts

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.