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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:58:44+00:00 2026-06-17T16:58:44+00:00

I have a iteration that is quite complicated, and each time through the loop,

  • 0

I have a iteration that is quite complicated, and each time through the loop, I have need for a ‘parameter’ that effects the work done in the loop. Basically, I have been doing the following:

CLOSE_SIDE = 0
FAR_SIDE = 1

....

while (...):
    if (side == CLOSE_SIDE):
        ....
    else if (side == FAR_SIDE):
        ....

    ....

    side = FAR_SIDE if (side == CLOSE_SIDE) else CLOSE_SIDE

I realize I could just use a boolean, but I feel like that reduced the readability and obviousness of what I’m doing. I would like the two states to be ‘named’. Also the assignment, though compact, feels very clunky. And doing a whole if statement:

if side == CLOSE_SIDE:
    side = FAR_SIDE
else if side == FAR_SIDE:
    side = CLOSE_SIDE

feels equally as clunky.

What is the best way to approach this? It’s more of a stylistic problem than anything. Would like some opinions from the community

  • 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-17T16:58:44+00:00Added an answer on June 17, 2026 at 4:58 pm

    Instead of naming the two values, you could choose an appropriate name for a bool variable and switch it between True and False:

    while (...):
        if far:
            ....
        else:
            ....
    
        ....
    
        far = not far
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that runs a model in a loop. Each iteration of
I have a piece of code which generates quite large lists in each iteration.
I have read that LinkedHashMap has faster iteration speed than HashMap because its elements
I have this code for my web application that I need some improvement, it
I have quite a big Arduino sketch that is pushing the limits of available
I am quite stuck here, need some guidance if it is possible! I have
I have a simple FOR loop inside of a batch file I'm creating that
Suppose I have a for loop that iterates over a generator and in this
I have a performance critical operation where I need to work with 1bpp images.
I have a background worker that stops after 100 iterations. Like this: BackgroundWorker bgWorker

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.