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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:32:57+00:00 2026-05-10T16:32:57+00:00

If you had to iterate through a loop 7 times, would you use: for

  • 0

If you had to iterate through a loop 7 times, would you use:

for (int i = 0; i < 7; i++) 

or:

for (int i = 0; i <= 6; i++) 

There are two considerations:

  • performance
  • readability

For performance I’m assuming Java or C#. Does it matter if ‘less than’ or ‘less than or equal to’ is used? If you have insight for a different language, please indicate which.

For readability I’m assuming 0-based arrays.

UPD: My mention of 0-based arrays may have confused things. I’m not talking about iterating through array elements. Just a general loop.

There is a good point below about using a constant to which would explain what this magic number is. So if I had ‘int NUMBER_OF_THINGS = 7‘ then ‘i <= NUMBER_OF_THINGS - 1‘ would look weird, wouldn’t it.

  • 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. 2026-05-10T16:32:57+00:00Added an answer on May 10, 2026 at 4:32 pm

    The first is more idiomatic. In particular, it indicates (in a 0-based sense) the number of iterations. When using something 1-based (e.g. JDBC, IIRC) I might be tempted to use <=. So:

    for (int i=0; i < count; i++) // For 0-based APIs  for (int i=1; i <= count; i++) // For 1-based APIs 

    I would expect the performance difference to be insignificantly small in real-world code.

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

Sidebar

Related Questions

I had to copy a datagridview to another, in order to iterate through it
If I had a file called raw_text.txt, is there a way I could iterate
How would I code a function to iterate through one pages worth of data?
In Python, if I had a range, and I wanted to iterate over it
Had a good read through similar topics but I can't quite a) find one
I had a debate about macros and their readability. I think that in some
Would there be any problems if I did the following to imitate a liked
My question: How can I break up and iterate through the JSON array pictured
I need an elegant way using VB.Net to iterate through a range of IP
Given a text file with multiple lines, I would like to iterate over each

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.