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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:38:21+00:00 2026-05-30T14:38:21+00:00

for (int ix = x – r; ix < x + r + 1;

  • 0
for (int ix = x - r; ix < x + r + 1; ix++) {
    for (int iz = z - r; iz < z + r + 1; iz++) {
        for (int iy = y - r; iy < y + r + 1; iy++) {
                       // if ix,iy,iz = something blah blah (this part isn't needed)
        }                           
    }
}

Ok, now here’s the issue. The current code above gets an x,y,z and r (range). It’s job is to reference through the “cube” until meets a certain condition I’ve set. The problem lies in the fact that it starts on the outside of the cube and progresses from 1 corner to another corner basically.

I’m looking for a way (my math/java is not liking me atm) to start at a pos and loop outwards from that pos (including the pos itself) until it reaches the outermost bounds of the cube.

So if we gave everything fake values, lets use x = 5, y = 5, z = 5, r = 2
the code should check 5,5,5 – 4,5,5 6,5,5 5,6,5 5,4,5 etc etc basically iterating through every thing to outwards from the center.

The command is called FindNearest, but technically it’s acting like FindFurthest atm.

I hope I gave enough detail and would love if someone could toss some snippets or working code at me as this is frustrating for the last hour or so. I don’t wanna have 10 if checks in the middle of the for loops or random stuff like that, I’m looking for a clean way of doing this.

  • 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-30T14:38:22+00:00Added an answer on May 30, 2026 at 2:38 pm

    You can iterate out from the center by doing something like this:

    for (ix = x, xsign = 1, xstep = 1; 
         (ix >= x - r) && (ix <= x + r);
         ix += xsign * xstep, xsign = -xsign, xstep++)
    

    So ix for your example will go from 5 to 6 to 4 to 7, etc. You can just nest loops like these and you’ll get what you’re looking for, at least if I’m understanding the question correctly.

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

Sidebar

Related Questions

int main(void) { std::string foo(foo); } My understanding is that the above code uses
int foo (int a , int b = 0) I just read this code.
int i=5; f() { i++; i--; } For the above code if three threads
int x = n / 3; // <-- make this faster // for instance
int m=32 printf(%x , ~m); Output of this statement is ffdf and without ~
int main() { int main=5; printf(%d,main); return 0; } In this case there is
int vote; Insertvotes(objectType, objectId , vote, userID); //calling For this method call, I want
int func(x) int x; { ............. What is this kind of declaration called? When
int LinkedList::DoStuff() { Node *Current = next_; while ( Current != NULL ) {
int item; cin >> item; That's in my code, but I want the user

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.