Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This is a style issue.

Both languages will ignore the usage of white space in this matter and therefore the style of "cuddling" your else's is valid in either language.

You can do however you please with your elses because the whitespace is ignored. The use of whitespace is important stylistically, as is indicated below, both uses are valid, but someone sight reading the code might miss that there is a loop at all in the first case, which begs the point that white space is still "important."

IE
while(condition){statement}

rather than

while(condition)
{
    statement
}
Really more important is that you delineate the code with tabs for readability regardless of what you do.

The } else { is a "cuddled else." It is important to note that cuddling just the else is considered mature coding style, not skipping the use of whitespace altogether. The reason behind this being that the else is really part of an if statement, not a separate statement as it appears to be when uncuddled (stylistically). This can be confusing to someone just learning coding and good style, so generally it is taught to just leave it uncuddled, so the line looks the same as it would on the if line. Cuddling just the else looks like this.

if (condition)
{
    statement
} else {    <== cuddled else
    statement
}


Just Another Perl Backpacker

In reply to RE: RE: Uncuddled else? by Nitsuj
in thread Uncuddled else? by footpad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (1)
As of 2024-04-24 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found