Loading ...
Sorry, an error occurred while loading the content.
 

Re: RE: [XP] How to code an infinite loop (was: What do you thinkaboutthese two coding idioms?)

Expand Messages
  • Kevin Smith
    ... How about: main() { while(ProcessInput()) ; } bool ProcessInput() { x = GetUsersChoice(); if(IsValid(x)) { Process(x); return true; } return false; } Or
    Message 1 of 1 , Feb 27, 2001
      >int x;
      >do
      >{
      > x = GetUsersChoice( );
      >} while ( TheUserHasntMadeAValidChoiceOf( x ) );

      How about:

      main()
      {
      while(ProcessInput())
      ;
      }

      bool ProcessInput()
      {
      x = GetUsersChoice();
      if(IsValid(x))
      {
      Process(x);
      return true;
      }
      return false;
      }

      Or something like that? Obviously there are
      variations if you absolutely hate returning from
      inside an if statement, or whatever.

      Kevin
    Your message has been successfully submitted and would be delivered to recipients shortly.