473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

PHP equiv of perl's last label or goto?

In a multiple nested structure I have a section that when true need to
break out of not only the current structure, but several more to read
a much higher level. In perl I would name/label my structures and use
the "last labelname" statement to accomplish this.

The PHP docs state that its break statement can take an optional
parameter which represents the "number" of levels to break out of.
Now this seems like it could work. However, I see a problem with
ongoing maintenance if someone inserts or removes another level which
would cause that number to be inaccurate.

Can someone please recommend how one might accomplish this feat using
flexible php code? I am all ears (well, eyes).

Thanks,

Bob
Mar 7 '06 #1
2 2014
NC
bobmct wrote:

In a multiple nested structure I have a section that when true need to
break out of not only the current structure, but several more to read
a much higher level. In perl I would name/label my structures and use
the "last labelname" statement to accomplish this.

The PHP docs state that its break statement can take an optional
parameter which represents the "number" of levels to break out of.
Now this seems like it could work. However, I see a problem with
ongoing maintenance if someone inserts or removes another level which
would cause that number to be inaccurate.

Can someone please recommend how one might accomplish this feat
using flexible php code? I am all ears (well, eyes).


Put the code into a function and break out using return().
Alternatively, use a flag variable:

$flag = true;
while ($flag) {
// some PHP code...
if ($some_condition) {
$flag = false;
}
// more PHP code...
if ($another_condition) {
$flag = false;
continue;
}
// yet more PHP code...
}

Cheers,
NC

Mar 7 '06 #2
bobmct wrote:
The PHP docs state that its break statement can take an optional
parameter which represents the "number" of levels to break out of.
Now this seems like it could work. However, I see a problem with
ongoing maintenance if someone inserts or removes another level which
would cause that number to be inaccurate.


The number of levels can be a variable rather than hard-coded, so there
might be scope to do something there, but it might be a bit nasty.

PHP's lack of "next" and "last" are a little irritating.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Mar 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

41
by: Xah Lee | last post by:
here's another interesting algorithmic exercise, again from part of a larger program in the previous series. Here's the original Perl documentation: =pod merge($pairings) takes a list of...
2
by: Wiseguy | last post by:
I'm in the process of trying to create my own lean, mean, uber linux distro and have bootstrapped a prototype system to build upon. I'm using the gcc 3.4.3 compiler and am getting an error that I...
2
by: Robert | last post by:
I have a label on my form lblCount and the following code in my form for displaying a record count: Private Sub Form_Current() Me.RecordsetClone.Bookmark = Me.Bookmark Me!lblCount.Caption =...
4
by: hisam | last post by:
How to use a label in c?? also how to call???
5
by: ReavenK | last post by:
I was doing a tutorial on inline assemble tricks for C and C++ when I came upon a little detail that I can't figure out. I was doing a test program to test out a concept which seems like it should...
1
by: anthonytngo | last post by:
I'm trying to retrieve the header for this website listed below. Is there a function to pull the header from this site? I was able to pull the header from my dos prompt using the HEAD funtion. The...
5
by: BF | last post by:
Hi, I have a problem: I am writing an update script for a database and want to check for the version and Goto the wright update script. So I read the version from a table and if it match I...
3
by: pilsdumps | last post by:
I have a simple class to create an html table: use strict; package clTableMaker; sub new { #constructor
8
numberwhun
by: numberwhun | last post by:
Hello everyone! I am dabbling in processing forms using Perl and having only just begun, I am already having problems. Go figure. :-) Top begin with, here it the form's html, its nothing at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.