note 98056 deleted from control-structures.goto by danbrown

From: Date: Mon, 24 May 2010 01:00:35 +0000
Subject: note 98056 deleted from control-structures.goto by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169538@lists.php.net to get a copy of this message
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; ?>

« previous php.notes (#169538) next »