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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:45:41+00:00 2026-05-11T20:45:41+00:00

I just found … AGAIN … a real time wastage bug as follows for

  • 0

I just found … AGAIN … a real time wastage bug as follows

for (int i = 0; i < length; i++)
{ //...Lots of code 
    for (int j = 0; i < length; j++)
    {
        //...Lots of code 
    }
}

Did you notice straight ahead the inner i which SHOULD BE j ? Neither did I. So from now on I am going to use:

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

What are your tips for inner and outer while and for loops ?

Edit: Thanks for the valuable responses. Herewith short summary of the proposed tips:

  • use meaningful variables names for index variables ( instead i use SomeObjCollectionLength )
  • place the contents of the inner loop into a separate method and call that method from the outer loop
  • not manageable amount of lines of code between the outer and inner loop is a strong signal for code smell
  • avoid copy pasting and rushing , write the index vars with care

You might want to check the summary by LBushkin for the following

  • use foreach and iterators whenever possible
  • initialize the variables just before entering the loops
  • Make each loop perform only one function. Avoid mixing responsibilities in a single loop
  • When possible, make your loops short enough to view all at once
  • 1 1 Answer
  • 1 View
  • 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-11T20:45:41+00:00Added an answer on May 11, 2026 at 8:45 pm

    Don’t use i & j (or any other single letter variable) as index names. Use proper names and you will not get into this type of problems.

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

Sidebar

Related Questions

Just found a bug in this code : for(String link : tempList1){ if(!tempList2.contains(link));{ listToPopulate.add(link);
I just found a nasty bug in my code because I captured a const
I just found out this weird behavior, is this a bug or what am
I just found out that every time onclick event for my <button> placed inside
I just found a bug in my Rails app which would lead to certain
Just found a piece of my code that had one original typo in it.
I just found a solution to one of the weirdest bug i have ever
I just found that when it comes to templates this code compiles in g++
I just found myself copying and pasting the same code twice. Right now I
I just found that not only does this code compile, it seems to split

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.