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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:46:30+00:00 2026-05-22T12:46:30+00:00

And to a lesser extent, what about a for loop with i<(n+1)? Would (n+1)

  • 0

And to a lesser extent, what about a for loop with i<(n+1)? Would (n+1) get evaluated once at start of loop or at every iteration?

for(int i=0; i<(n+1); i++){  
   // Do something
}

for(int i=0; i<=n; i++){  
   //Do something
}

UPDATE:
As suggested by nearly everyone, I ran a simple test with three loop variations i

  • 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-05-22T12:46:31+00:00Added an answer on May 22, 2026 at 12:46 pm

    It would likely depend on whether or not the value of n was changing over the course of the loop. If not, I would think that any modern compiler would cache the value of n+1, rather than calculating it each iteration. Of course that’s not a guarantee, and with no optimizations, n+1 would be evaluated each time.

    EDIT: To answer the title question, i < n vs. i <= n would have no noticeable difference (other than an extra iteration, assuming the n’s were equal in both cases.) CPUs have single ops for both comparisons.

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

Sidebar

Related Questions

I need to get the lesser n numbers of a list in Python. I
I'm new to Scheme (via Racket) and (to a lesser extent) functional programming, and
After five years of professional Java (and to a lesser extent, Python) programming and
I have a few related questions about managing aligned memory blocks. Cross-platform answers would
I'm trying to get a HTML email to print a table at a lesser
I am writing an application where memory, and to a lesser extent speed, are
What are your favorite lesser-known gems/plugins for Rails? This question about Rails plugins brought
What are some of the lesser know, but important and useful features of Windows
In IE6 (but also seen in 7 and to a lesser extend 8) I
What are some lesser known tips for implementing a loosely-coupled MVC structure in a

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.