🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14771

Re: Your Openion needed.

#14771
From: Tor Iver Wilhelmsen
Date: Mon, 09 Aug 1999 00:00
34 lines
1200 bytes
"Dillan Fernando" <dillan@geocities.com> writes:

> public boolean dummy()
> {    for(a=0;a<x;a++)
>     {    if (a==b) return true
>     }
> return false;
> }

Procedural programmers will balk at it and mumble something about
"single exit point": to please them, rewrite it like this:

public boolean dummy() {
  boolean retVal = false;
  loop: for (int a = 0; a < x; a++) {
    if (a == b) {
      retVal = true;
      break loop;
    }
  }
  return retVal;
} 
  
Note: The "loop" label here is redundant, and only there for
readability purposes.

(I assume your sample code was just an illiustration: The method below
is a much faster version:

 public void dummy() {
   return ((b >= 0) && (b < x));
 }

)
Technical Details
Message-ID: <ug11txunm.fsf@sds.no>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7oksdc$5pa2@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,ead9ef4a7993b06e
X-Google-Attributes: gidf74b3,public
From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no>
Subject: Re: Your Openion needed.
Date: 1999/08/09
Message-ID: <ug11txunm.fsf@sds.no>
X-Deja-AN: 510517936
Sender: towi@SDSA1761
References: <7oksdc$5pa2@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language