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

The Archive Base Latest Questions

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

Okay this is going to seem really dumb but bear with me please. A

  • 0

Okay this is going to seem really dumb but bear with me please. A year ago I made a little program to perform various operations on images, and now I’m a bit rusty and having to do something vaguely similar. I’m looking at the old application in order to help me get started but there is one very simple thing my head doesn’t want to understand the logic of just now. Basically where I loop through each pixel in an image in order to do something with that location, what exactly doesn’t matter right now. Here is the basic idea:

for (int x = 0; x < inputImage.getWidth(); x++) {
    for(int y = 0; y < inputImage.getHeight(); y++) {
        *code in here*
    }
}

Now what I don’t get is this. Surely the logic of the nested for loops means that after every loop, both x AND y are incremented. So on the first pass, x = 0, y = 0. Second pass, x = 1, y = 1 and so on. This would mean that you only ever choose diagonal pixels going from the top left of the image to the bottom right, missing out a ton of pixels such as one located at x = 0, y = 1. I KNOW this is simple and surely makes sense but I’m just not getting the logic right now! Many thanks.

  • 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-26T16:53:11+00:00Added an answer on May 26, 2026 at 4:53 pm

    No, that’s not what nested loops do at all. The y loop is wholly inside the body of the x loop (that’s what it means to be nested), so the entire y loop runs at each iteration of the x loop.

    x = 0
       y = 0, y = 1, y = 2, ...
    x = 1
       y = 0, y = 1, y = 2, ...
    

    The behavior you’re thinking of, with only iterating over diagonal elements, could be achieved like this if you wanted it:

    for (int x = 0, int y = 0;
               x < inputImage.getWidth && y < inputImage.getHeight;
               x++, y++) {
         // stuff
    }
    

    Notice how both x and y are incremented in the same loop; there is no nested “subloop”. (Disclaimer: I haven’t done Java in a while, I might have messed up the syntax a bit)

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

Sidebar

Related Questions

Okay this is probably a really dumb question, however it's really starting to hurt.
Okay this one may be a bit out from left field, but I'm going
Okay, the question might seem dumb, but I'm asking it anyways. After struggling for
Okay, for whatever reason I can't seem to figure this little problem out. I
Okay this may be a simple question but I have yet to come with
okay so this is probably a soft pitch question for sombody, but I want
Okay I am probably going to get a load of down votes for this
Okay, I've been reading about rvalues and they seem like a great idea, but
Okay. Complex Title for a simple(?) problem. I have something like this going on
Okay. Complex Title for a simple(?) problem. I have something like this going on

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.