Go to Statement in PHP Prepared By
www.CreativeDev.in
Go To in PHP • Goto statement is only available in latest version of PHP and its PHP 5.3 or higher PHP versions.We can say Goto statement is used to jump to other section of the program. • The Goto Statement requires a label to identify the place where the branch to be made. A label is any valid variable name and must be followed by colon(:). A label is immediately placed before the statement where the control is to be transferred.
The general form of Goto:
Some Important Notes • The label: can be in anywhere in the program before or after the gotolabel; statement. • goto is not a function. Its just a statement. • When program run and get the statement like go to first; the flow of program will jump to the statement first: .This occurs unconditionally.
Example echo "Lets start with Go To"."<br />"; goto read; echo "Skip the code with Goto jump"; read: echo "Execute the code with Goto jump";
OutPUT Lets start with Go To Execute the code with Goto jump
Last but not least • In the previous example, when the code encounters the goto statement, the control transfer to the label “read”. • "Dont go to GO TO statement".Try to avoid the use of goto as far as possible but there is nothing wrong if we use it to improve execution speed of program.
Thank You ď &#x160; Feel free to add your comments/queries on
http://www.creativedev.in/2011/11/goto-statement For more articles, visit: www.creativedev.in