note 98056 deleted from control-structures.goto by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: edgar dot klerks at gmail dot com 

----

Better not use it, it has to power to make your code unstructured. To illustrate this danger, I made an especially bad example of using gotos. 
 
<?php
/* Fibonaci and goto */
start:
print  "Please give a number:";
$n = (int)fgets(STDIN) - 1;
if(!isset($x))
        $x = array(1,1);
$last = $i = 0;
$back = 'nextstep';
goto fib;
nextstep:
$t = 0;
$sum = 0;
sum:
print_r($x) ."\n";
if($t > $n){
        goto result;
}
$sum += $x[$t];
$t++;
goto sum;
result:
print "The sum is: " . $sum . "\n";
goto start;
jmpspot:
switch($back){
        case 'nextstep':
                goto nextstep;
                break;
        default:
                goto start;
}
fib:
if($last > $n){
        $i = $n;
        goto jmpspot;
}
if(!isset($x[$i]))
        $x[$i] = $x[$i - 1] + $x[$i - 2];
if($i > $n)
        goto jmpspot;
$last = $i;
$i++;
goto fib;
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.