FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » AND and OR
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: AND and OR [message #182571 is a reply to message #182569] Fri, 16 August 2013 11:24 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
On 16/08/13 11:48, Norman Peelman wrote:
> On 08/16/2013 06:25 AM, The Natural Philosopher wrote:
>> On 16/08/13 01:21, Twayne wrote:
>>> Hi,
>>>
>>> Doing code cleanup; something that seemed so simple is giving me lots
>>> of trouble for whatever reason.
>>>
>>> Win 7, XAMPP, PHP 5.3, online forms:
>>>
>>> In my cleanup efforts I've been trying to concatenate statements for
>>> things like the following:
>>>
>>> IF(strlen(var1) == 0) OR strlen(var2) == 0) OR strlen(var3) ==0))
>>> {
>>> code; notify user of errors that must be corrected.
>>> }
>>>
>>> I know OR is || and AND is &&, and have tried every combination of
>>> code I can think of but I consistently get syntax errors and it never
>>> works.
>>> Doing each var independently works fine; e.g. if(strlen($var) == 0)
>>> {...}, works as expected, first time every time.
>>>
>>
>> your brackets are screwed.
>>
>> if ((strlen(var1) == 0) || (strlen(var2) == 0) || (strlen(var3) ==0))
>>
>> will work
>> as will
>> if (strlen(var1) == 0 || strlen(var2) == 0 || strlen(var3) ==0)
>>
>
> As well as:
>
> if (!strlen(var1) || !strlen(var2) || !strlen(var3))
>
>
Yebbut, for twayne, that may be taking things a step too far..

many many years ago when I was a real noob and learning C without the
benefit of any training courses, I had to revisit some code to find two
bugs in it. The new person who had taken over asked me why I had never
used a particular language construct. I replied 'because at the time, I
didn't know it existed'

Trainee coders are often dumped into maintenance. One should be kind to
them. And with advances in modern compilers, there is no speed or
compiled code size penalty in being explicit at the source code level.

We were all noobs once.

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Function Problem
Next Topic: switch with case 0
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 09 12:13:52 GMT 2024

Total time taken to generate the page: 0.07306 seconds