0

Hi,
I am new in php.I want to use goto statement inside my program.But when i execute the below coding the blank page appears.This is the example program i referred in site.

Coding:
goto a;
echo 'Foo';

a:
echo 'Bar';

Help me..
Thanks :-O

8
Contributors
10
Replies
12
Views
7 Years
Discussion Span
Last Post by Zagga
0

It means you don't have the latest version of php. The goto element is only available in the latest release (5.3) but I wouldn't recommend it due to incompatibility bugs. Instead try using loops and if statements such as the following:

<?php
if (false) {
echo 'Foo';
}
echo 'Bar';
?>
0

There doesnt seem to be any errors in the code you are using. It should definitely be a problem with the version.
The goto operator is available only as of PHP 5.3

Please check your PHP version

0

goto is a throw-back to the 1960s and is generally considered a bad thing. It generated what is called spaghetti code and programmers are advised to avoid using it. It was a much loathed method of causing problems and has been expunged from almost all programming languages due to endless mis-use and abuse.

Use if, as suggested earlier or call a function rather than jumping to it and then returning. Or a switch / case set. Or anything else you can think of.

0

goto is a throw-back to the 1960s and is generally considered a bad thing. It generated what is called spaghetti code and programmers are advised to avoid using it. It was a much loathed method of causing problems and has been expunged from almost all programming languages due to endless mis-use and abuse.

Use if, as suggested earlier or call a function rather than jumping to it and then returning. Or a switch / case set. Or anything else you can think of.

Couldn't agree more. I used to use GOTO in VB when I was too lazy to code it properly (create functions). Of all the php I've ever written, I've never found the need to use a GOTO. Anybody know why it was introduced in 5.3?

0

Of all the php I've ever written, I've never found the need to use a GOTO. Anybody know why it was introduced in 5.3?

Mhh! as I was reading the post the same question came to my mind. Why would it be needed not only in PHP but also in other language like C++? Don't get mad at me cwarn (remember SHA1 cracker?)
That infamous gOtO ;)

0

Mhh! as I was reading the post the same question came to my mind. Why would it be needed not only in PHP but also in other language like C++? Don't get mad at me cwarn (remember SHA1 cracker?)
That infamous gOtO ;)

The reason I used the goto tag in c++ is because I was too lazy to make an infinit loop. But yes there are methods to use in any language which posses loops. I believe the goto tag was originally used before loops had been invented. But when new/current languages came out with the loop mechanism there was no need to use the goto unless your lazy or unexperienced.

0

I used to use GOTO in VB when I was too lazy to code it properly (create functions).

The reason I used the goto tag in c++ is because I was too lazy to make an infinit loop.

Mhh! Programmers are bunch of lazy people? Although don't use goto, I know I'm fond of those "lazy" shortcuts

0

Oh my. GOTO?

I havent heard that since the days of the VIC20, when you used to have to type in line numbers too :)

Zagga

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.