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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:48:22+00:00 2026-05-21T05:48:22+00:00

I have a very long loop, and I would like to check the status

  • 0

I have a very long loop, and I would like to check the status every N iterations, in my specific case I have a loop of 10 million elements and I want to print a short report every millionth iteration.

So, currently I am doing just (n is the iteration counter):

if (n % 1000000==0):
    print('Progress report...')

but I am worried I am slowing down the process by computing the modulus at each iteration, as one iteration lasts just few milliseconds.

Is there a better way to do this? Or shouldn’t I worry at all about the modulus operation?

  • 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-21T05:48:23+00:00Added an answer on May 21, 2026 at 5:48 am

    How about keeping a counter and resetting it to zero when you reach the wanted number? Adding and checking equality is faster than modulo.

    printcounter = 0
    
    # Whatever a while loop is in Python
    while (...):   
        ...
        if (printcounter == 1000000):
            print('Progress report...')
            printcounter = 0
        ...
        printcounter += 1
    

    Although it’s quite possible that the compiler is doing some sort of optimization like this for you already… but this may give you some peace of mind.

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

Sidebar

Related Questions

I have very long multidimensional array that have many sub arrays. I would like
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now
I have a very long String and I want to read character by character
Assume I have a loop (any while or for) like this: loop{ A long
I have a very long-running stored procedure in SQL Server 2005 that I'm trying
I have a very long javascript (so long that it's too long to escape
We have a very long form that has a number of fields and 2
I have a very long table in my webpage. When I print it, it
I have a very long text and I need to hide everything except the
As background I have a very long ID that too long to display in

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.