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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:57:19+00:00 2026-06-12T07:57:19+00:00

I have a while loop with a switch statement: while(true) { switch(state) { case

  • 0

I have a while loop with a switch statement:

while(true) {
        switch(state) {
        case LOADING :
            //THIS IS THE IMPORTANT PART
            //view loading screen (already set by default)
            contentPane.repaint();
            if(tick == 400000) {
                //state = GameState.MENU;
                System.out.println("Reached " + gameTick);
            }
            break;
        case MENU :
            //view menu
            break;
        //some other cases without content, left them out here
        }
        tick++;
        if(tick < 400000) {
                System.out.println(tick);
        }
        if(tick == Long.MAX_VALUE) {
            tick = 0;
        }
    }

Now this code executes just fine, it shows the loading screen (which has moving dots on it for as long as it’s repaint is repeatedly called, so I know exactly when it stops), and the output counts from 1 to 400000 and on that number prints

399998
399999
Reached 400000    

(last 3 lines of output)

The application goes fullscreen, and when I alt+tab out, the counter is usually somewhere around 130K, and I watch it move to 400K.

However, if I remove the if statement that prints this number:

if(tick < 400000) {
    System.out.println(tick);
}

The loading screen never moves, and when I alt + tab out, the 400K is already reached.

Also curious is that the loading screen has three ‘appearance changes’, one at 100 calls of it’s paintComponent method, one at 200 calls and one at 300 calls, which resets the counter to 0. So basically, every 100 ticks it’s supposed to have an appearance change. In the first case, with the if-statement, which has longer execution time, I see the changes but by far not as frequently as I’d expect. In the second case, I don’t see them at all (I can imagine they’d happen too fast).

So my question is, what creates this quite big difference in execution time, and what causes the difference in the amount of times the paintComponent method seems to be called, and the 400.000 times the loop iterates?

All ideas appreceated.

  • 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-12T07:57:20+00:00Added an answer on June 12, 2026 at 7:57 am

    Writing to the console, especially the MS-DOS console, is very very slow. You should try to keep the number of lines you write to the console to a minimum. If you have to write lots of data I suggest you write it to a file as it can be significantly faster.

    I assume this is done in another thread and you are not tying up the GUI thread.

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

Sidebar

Related Questions

I have this message loop in my program: while (true) { if (PeekMessage(&msg, window,
I have some javascript code with do while outer loop and switch inner loop,
I have a tabled view in a while loop, where a user can view
I have the following code with the if...else statement within a while loop. $colour
I have a while loop that loops until bool done = true; In the
The while loop I have while reading in from a file doesn't break. I'm
I have a while loop that goes while a BuffedReader still has data, what
I have a while loop that loops through 3 results and echo's these out
hi i have a while loop: var i = 0; while(i < 20) {
So with pygame you have a while loop that loops continuously, then your event

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.