Today, we've got a triple-header of stuff that's probably too short to post on its own. The theme, briefly: loops. (Because who doesn't love loops? I know I do!)

Where Mike works, they reward people for thinking outside of the box. He didn't find this code (a coworker did) but he did give it a gold star for breaking the mold.

 

  for ( int i = 1 ; i <= 10 ; i++ )
  {
      /* do something important */
      if ( condition ) i = 11;
      /* do something else important */
  }

 

Mike says, "At least it works." Where Bill works, they have heard of (and use) break. Unfortunately, they use it like this.

 

  long StringToLong( String s )
  {
      for ( int j = 0 ; j < s.length() ; j++ )
      {
          if ( s.chatAt(0) == '0' )
          {
              s = s.substring(1);
          }
          else
          {
              break;
          }
      }
      return Long.parseLong( s );
  }

 

Those guys have it easy. Where Dave works, someone is having trouble with white-space. (They use C# but maybe this is a sign that they should switch to Python.)

  foreach ( Term t in current )
      if ( category == "" )
      {
          result = t;
          break;
      }
      else
          if ( t.category == category )
              result = t;
          if ( result == null ) return;
              return result;