note 98056 added to control-structures.goto

From: Date: Mon, 24 May 2010 00:31:32 +0000
Subject: note 98056 added to control-structures.goto
Groups: php.notes 
Request: Send a blank email to php-notes+get-169536@lists.php.net to get a copy of this message
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; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 195.241.100.248 ---- Manual Page -- http://www.php.net/manual/en/control-structures.goto.php Edit -- https://master.php.net/note/edit/98056 Del: integrated -- https://master.php.net/note/delete/98056/integrated Del: useless -- https://master.php.net/note/delete/98056/useless Del: bad code -- https://master.php.net/note/delete/98056/bad+code Del: spam -- https://master.php.net/note/delete/98056/spam Del: non-english -- https://master.php.net/note/delete/98056/non-english Del: in docs -- https://master.php.net/note/delete/98056/in+docs Del: other reasons-- https://master.php.net/note/delete/98056 Reject -- https://master.php.net/note/reject/98056 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#169536) next »