|
Posted by Jerry Stuckle on 04/18/07 17:23
Rami Elomaa wrote:
> Steve kirjoitti:
>> "Rami Elomaa" <rami.elomaa@gmail.com> wrote in message
>> news:vNkVh.38543$8H5.25109@reader1.news.saunalahti.fi...
>> | "Toby A Inkster" <usenet200703@tobyinkster.co.uk> wrote in message
>> | news:v1ugf4-9qv.ln1@ophelia.g5n.co.uk...
>> | > Rami Elomaa wrote:
>> | >
>> | >> <?php
>> | >> $i++;
>> | >> if($i<10) xyz (__FILE__) ;
>> | >> else echo $i;
>> | >> ?>
>> | >>
>> | >> Substitute xyz with a standard function or construct so that the
>> output
>> | >> is 10.
>> | >
>> | > My immediate thought would be...
>> | >
>> | > <?php
>> | > $i++;
>> | > if($i<10) echo
>> preg_replace('/[^\d]/','',file_get_contents(__FILE__));
>> | > else echo $i;
>> | > ?>
>> | >
>> |
>> |
>> | Well, that's quite a brilliant solution, but the goal was to use one
>> and
>> | only one function substituting xyz, but you've used three. This was
>> my fault
>> | since I couldn't describe the task correctly. English isn't my native
>> | language and it was late in the evening... Let me try to rephrase the
>> | question:
>> |
>> | <?php
>> | $i++;
>> | if($i<=9)
>> | xyz (__FILE__) ;
>> | else
>> | echo $i;
>> | ?>
>>
>> rami, you've REALLY got to work on your single line if/else formatting.
>
> Please show me the correct formatting. I tried two combinations which
> both seem to me ok and understandable, and you've banned both of them.
> I'm all out of ideas. It would be REALLY helpful if you could point out
> what is wrong with these and secondly what is the correct way. What am I
> supposed to do?
>
Rami,
There are all kinds of conventions for formatting code. Steve gave you
one, and one of the most popular.
Look at some of the example code in the PHP manual, for instance. And
other code posted here in the newsgroup and around the net.
Not all of it adheres to the same conventions, but you'll soon recognize
many of them.
I like this convention because it makes the code much easier to read and
understand. For instance, I find putting the "then" clause on the same
line as the "if" statement more difficult to read. I guess mainly
because the "if" statement is always executed, but the "then" clause may
or may not be. Placing it on another line helps clarify that.
And indenting under "if" statements, loops, function definitions, etc.
are a very good way to help see program flow.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|