Re: speaking of control structures...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



im not sure if i understand exactly what you want. but from what ive gathered, did you try to make use of a FUNCTION?
<?php
function add($val1,$val2) {
   return ($val1 + $val2); //returns value from where it was called.
}

function doit(){
   if() {
       bla bla bla;
   }
   else blar;
   etc...
   return; // this just returns, can also be left out.
}

$added = add(1,2);
echo $added;
doit();

?>

"Tom Worster" <fsb@xxxxxxxxxx> wrote in message news:C625F5F7.A80F%fsb@xxxxxxxxxxxxx
there's a control structure i wish php had: a simple block that you can
break out of, e.g.

block {

 if ( condition )
   break;

 blah...
 blah...

 if ( another condition )
   break;

 blah...
 blah...

 etc...

}

the block is just like a loop except that it is executed once only.

this would be a handy structure for writing input validation code. the blah
blah fragments can be used for opening files, talking to the db,
manipulating strings, processing dates and times, etc., the conditions for
testing if the input is unacceptable.

i'm sure many of the programmers here do this kind of thing routinely and
have their own habits and solutions. i'd be curious what they are. please
let us know!


i guess i ought to go first. it's fugly but it works:

$once = true;
while ( $once ) {
 $once = false;

 stuff using break where needed ...

}

tom



__________ Information from ESET Smart Security, version of virus signature database 4054 (20090505) __________

The message was checked by ESET Smart Security.

http://www.eset.com





__________ Information from ESET Smart Security, version of virus signature database 4054 (20090505) __________

The message was checked by ESET Smart Security.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux