title: SDL2 main game loop
body: <p>My question popped out while reading the tutorials on SDL2, on lazyfoo.net and the code is being copied from  <a href="http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php" rel="nofollow">this page</a></p>
  
  <pre><code>int main( int argc, char* args[] )
  {
  
  //Start up SDL and create window
  
  if( !init() )
  {
      printf( "Failed to initialize!\n" );
  }
  else
  {
      //Load media
      if( !loadMedia() )
      {
          printf( "Failed to load media!\n" );
      }
      else
      {
          //Main loop flag
          bool quit = false;
  
          //Event handler
          SDL_Event e;
  
          //While application is running
          while( !quit )
          {
              //Handle events on queue
              while( SDL_PollEvent( &amp;e ) != 0 )
              {
                  //User requests quit
                  if( e.type == SDL_QUIT )
                  {
                      quit = true;
                  }
              }
  
              //Clear screen
              SDL_RenderClear( gRenderer );
  
              //Render texture to screen
              SDL_RenderCopy( gRenderer, gTexture, NULL, NULL );
  
              //Update screen
              SDL_RenderPresent( gRenderer );
          }
      }
  }
  
  //Free resources and close SDL
  close();
  
  return 0;
  }
  </code></pre>
  
  <p>Here why are we rendering the effects inside the main loop and make it run again and again rather than like:</p>
  
  <pre><code>int main( int argc, char* args[] )
  {
  //Start up SDL and create window
  if( !init() )
  {
      printf( "Failed to initialize!\n" );
  }
  else
  {
      //Load media
      if( !loadMedia() )
      {
          printf( "Failed to load media!\n" );
      }
      else
      {
          //Main loop flag
          bool quit = false;
  
          //Event handler
          SDL_Event e;
  
         //Clear screen
         SDL_RenderClear( gRenderer );
  
          //Render texture to screen
          SDL_RenderCopy( gRenderer, gTexture, NULL, NULL );
  
          //Update screen
          SDL_RenderPresent( gRenderer );
  
          //While application is running
          while( !quit )
          {
              //Handle events on queue
              while( SDL_PollEvent( &amp;e ) != 0 )
              {
                  //User requests quit
                  if( e.type == SDL_QUIT )
                  {
                      quit = true;
                  }
              }
          }
      }
  }
  
  //Free resources and close SDL
  close();
  
  return 0;
  }
  </code></pre>
  
  <p>I suppose there is a reason as this is done in many tutorials.
  But i am unable to get the reason.</p>