473,394 Members | 1,726 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,394 software developers and data experts.

if an multiple statements

another topic though related to the previous post.

How do IF behave in php?

Say,
if( $goahead && copy($somefile1, $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?

I can make a complex if system, but eventuallt I can keep it simple
here...
Jan 7 '08 #1
6 1586
On Mon, 07 Jan 2008 17:24:29 +0100, jodleren <so*****@hot.eewrote:
if( $goahead && copy($somefile1, $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?
In PHP, failure of $goahead will mean copy() is not checked/executed in
this case.
I can make a complex if system, but eventuallt I can keep it simple
here...
Well, short from a programmers standpoint indeed. Being more verbose often
doesn't hurt though, and makes code somewhat more flexible/debuggable.
Depends on the actual need offcourse.
--
Rik Wasmus
Jan 7 '08 #2
..oO(jodleren)
>How do IF behave in php?

Say,
if( $goahead && copy($somefile1, $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?
PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

$rs = mysql_query(...) or die(...);

Micha
Jan 7 '08 #3

"Michael Fesser" <ne*****@gmx.dewrote in message
news:pm********************************@4ax.com...
.oO(jodleren)
>>How do IF behave in php?

Say,
if( $goahead && copy($somefile1, $somefile2) )
echo "hello world";

What if $goahead is false, will the if the fall, or test all of the
statements?

PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like
more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?

most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.

cheers.
Jan 7 '08 #4
..oO(Steve)
>"Michael Fesser" <ne*****@gmx.dewrote in message
news:pm********************************@4ax.com.. .
>PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?
Correct, and one common name for that technique is "lazy evaluation" (or
"delayed evaluation"): the result of an expression is only calculated if
and when it's really necessary.
>most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.
AFAIK "short-circuit" is more related to logical expressions, whereas
"lazy evaluation" is the more general name and applies to many other
things as well.

Micha
Jan 7 '08 #5

"Michael Fesser" <ne*****@gmx.dewrote in message
news:75********************************@4ax.com...
.oO(Steve)
>>"Michael Fesser" <ne*****@gmx.dewrote in message
news:pm********************************@4ax.com. ..
>>PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like

more pragmatic than lazy. if one condition is false, there is no possible
way other &&'ed conditions could change that result...so, why continue the
evaluation?

Correct, and one common name for that technique is "lazy evaluation" (or
"delayed evaluation"): the result of an expression is only calculated if
and when it's really necessary.
>>most languages do it this way. of those that i've used, vb was the only
one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added -
'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.

AFAIK "short-circuit" is more related to logical expressions, whereas
"lazy evaluation" is the more general name and applies to many other
things as well.
hmmm...i didn't know that. first i'd heard of lazy eval.
Jan 7 '08 #6
On Jan 7, 6:54*pm, "Steve" <no....@example.comwrote:
"Michael Fesser" <neti...@gmx.dewrote in message
PHP uses lazy evaluation. As soon as the result is known, the evaluation
stops. Because of this behaviour you can write things like
most languages do it this way. of those that i've used, vb was the only one
that continued to blindly evaluate conditions. it wasn't until vb.net that
the AndAlso and OrElse short-circuit constructs were added - 'short-circuit'
being even more descriptive than 'lazy' or 'pragmatic'.
Well I would think the same way, but as you wrote, once tried VB one
knows, that one has to be careful...
There are really a lot of languages and scripts out there, so better
safe than not.

As for debugging/reading of code - this can really minimise code, and
by that give a better overview. Some may think it is a bit harder to
read, but I rather have a few lines of code than 3 screens of it.

Thanks, all
Jan 8 '08 #7

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

Similar topics

0
by: Tim Hastings | last post by:
Hello, I am using MyODBC from VB and I want to submit a batch of insert statements in one call from my App. This is more efficient than making multiple calls from code because of the...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
7
by: Glenn Davy | last post by:
Hidely hodley everyone I'd like to run a series of of sql ddl statements against an msde2000 server. Normally I just deploy cmd file that impliments as osql statement, but I'd like to store the...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
24
by: sureshjayaram | last post by:
In some functions where i need to return multiple error codes at multiple places, I use multiple return statements. Say for ex. if (Found == 1) { if (val == -1) return error1; } else { if...
6
by: G.Ashok | last post by:
Hi, Does anybody know how Multiple polymorphism can be done in VB.NET or DOT doesn't support it? Is there any third party extensions available like for Java to do this? Regards, ....Ashok...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have coded multiple select statements in a single stored procedure, and when I execute this procedure on SQL Server Management Express, I correctly get multiple result sets. But, if I try to add...
3
by: Tim | last post by:
Hi Folks, I'm used to a UNLOAD command that allows me to dump to a named flat file the results of any SELECT statement. Hence one can build a single SQL file which contains multiple SQL...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.