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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:55:41+00:00 2026-06-09T18:55:41+00:00

I have a for loop that searches an array of structures in order to

  • 0

I have a for loop that searches an array of structures in order to find a specific structure.
Now this array may be of size 10000.

Inside the for loop I might gather some extra information that will tell me where exactly is the structure you are looking for. So if your index is currently ‘5’, you might find out that it’s not in ‘5’ but in ‘9000’.

So I use this information in order to change the index.

Now the code works perfectly fine without changing the index in the sense that it does find the information needed. However if I’m 100% sure that what I’m doing is correct in this case, is it OK to change the index in the for loop in order to get results faster?

Thanks in advance

  • 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-09T18:55:42+00:00Added an answer on June 9, 2026 at 6:55 pm

    It’s absolutely fine. The language doesn’t distinguish between changing the index in the loop body and changing it in the increment statement within the loop header.

    for (initializer-statement; condition-statement; increment-statement)
        loop-body;
    

    is mostly equivalent to

    {
        initializer-statement;
        while (condition-statement) {
            loop-body;
            increment-statement;
        }
    }
    

    One difference is that a continue statement within the loop body of a for loop will still execute the increment-statement, which could cause problems if you’re not expecting it.

    Also be careful that you don’t create an infinite loop by overrunning your terminating condition.

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

Sidebar

Related Questions

I have a loop that can look like this: For Each article In artAll
I have a page that searches a database and generates the following array. I'd
I have a loop that enters each non-empty text field into a database: foreach
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop that runs through a variety of websites and I'd like
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100
I have a loop that calculates the similarity between two documents. It collects all
I have a loop that goes through all the news items we have on
I have a loop that works but not when I try and use it
I have a loop that builds a table with camera names. In that table

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.