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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:36:10+00:00 2026-06-01T04:36:10+00:00

I have loop for: for (int i = 1; i < 2000; i++) How

  • 0

I have loop for:

for (int i = 1; i < 2000; i++)

How I can change this loop that instead of int < 2000 I can get time:

for (int i = 1; i < 2000(miliseconds); i++)

I want to do this loop until time is less then 2000 miliseconds.I mean that this loop must working for 2 seconds and after 2 sec break.

In loop I doing some operations. I save position of cursor. I want save that position for 2 seconds.

  • 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-01T04:36:12+00:00Added an answer on June 1, 2026 at 4:36 am

    Assuming you want to do something in a loop until 2000ms has passed:

    long then = new Date().getTime() + 2000/*ms*/;
    do {
      // Do some work here...
      long now = new Date().getTime();
    } while (now < then);
    

    [Edit] As commenter @CheJami points out, there’s no need to create a Date object since you can get the current time in milliseconds directly:

    long then = System.currentTimeMillis() + 2000/*ms*/;
    do {
      // Do some work here...
      long now = System.currentTimeMillis();
    } while (now < then);
    

    This strategy will likely result in better performance overall since there is no need to repeatedly create new objects and eventually garbage collect them.

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

Sidebar

Related Questions

Suppose I have a vector<int> myvec and I want to loop through all of
Hello is this possible in c#: If I have a loop say: int x
I have this for loop: int iPanelNumber = 1; foreach (string[] Persons in alItems)
I have a Loop like this int numberofelements=20; for(int i=0;i<numberofelements;i++) { if(i==numberofelements) { break;
In C/C++, I can have the following loop for(int k = 1; k <=
I have the following loop in my viewDidLoad: for(int i=1; i<[eventsArray count]; i++) {
I have the next for loop header: for ( int row = interval[intRow][_START_]; row
I have a for loop generating integers. For instance: for (int i=300; i>200; i--)
I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
I have a loop that reads each line in a file using getline() :

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.