Re: what does two semicolns ';;' do



In article <g4kh6453kqnfu1lddaee4qi6407mkovt76@xxxxxxx>,
Michael Fesser <netizen@xxxxxx> wrote:

.oO(Tim Streater)

In article <ivgh64ll18rvnv95q6noc13cadab4r17uh@xxxxxxx>,
Michael Fesser <netizen@xxxxxx> wrote:

Pest or cholera. You also have to use a break to leave the while loop.
IMHO infinite loops are always ugly and bad coding style, regardless of
how you code them.

Not necessarily. I would always use while (true), as then you make
explicit what you are doing. Secondly, sure you have to break out of the
loop. But suppose there's a number of different reasons to do so? You're
not necessarily going to be able to choose one as the "main driver" of
the loop, which ought then to migrate into the loop construct?

You could still find a better way to express the loop condition, even if
it's just a variable:

while (!$workIsDone) {
...
}

I admit that I also use break/continue from time to time, but I try to
avoid them because they often lead to hard to understand spaghetti code.
There's almost always a better way to structure the code.

Here's some code from a simple app I am working on:

foreach ($attstrs as $nextatt)
{
if ($nextatt=='') continue;
$nextatt = "/Volumes/" . str_replace (":", "/", $nextatt);
$handle2 = fopen ($nextatt, "rb");
if ($handle2===false)
{
echo "Error - could not open attachment:\n '" . $nextatt .
"'\n";
continue;
}

...

}

Two continues in there. The alternative is to nest the code deeper,
something I avoid like the plague.
.



Relevant Pages

  • Re: what does two semicolns ;; do
    ... Michael Fesser wrote: ... sure you have to break out of the loop. ... Good programmers write clean code, not code that is 0.01% faster, but clean code. ... It is a horror to read over code written by would-be programmers that is aimed at speed, or people trying to keep the sourcefiles as small as possible. ...
    (comp.lang.php)
  • Re: Question on conditional statements
    ... Michael Fesser wrote: ... >>When running through a loop, how can you test two separate conditions ... >>against the same $element of an array. ...
    (comp.lang.php)
  • Re: something like grep
    ... Michael Fesser wrote: ... tree. ... to loop through a directory and all that's beneath it if necessary. ...
    (comp.lang.php)
  • Re: what does two semicolns ;; do
    ... Michael Fesser wrote: ... IMHO infinite loops are always ugly and bad coding style, regardless of ... sure you have to break out of the loop. ... That way there is an explicit test at the top of the loop and I don't have to use "break". ...
    (comp.lang.php)
  • Re: How to set up a global variable in a sub-routine?
    ... the 'global variables' are more like constants ... ... single script, I need a way to tell it only once where the file is and ... So, if you construct a loop with a loop variable, you ... >programmers avoid global variables completely. ...
    (perl.beginners)