Would a kind monk explain what rules C uses to terminate a block
If there's a block, then the rules are the same as in Perl. But if there's no block, then it's a bit more complicated.

Basically, C expects to see either a statement, or a block. A C statement is either something straightfoward (typically an expression, but it could even be nothing) that ends in a semicolon, or it could be a if or a for control structure, or other similar control structures such those with if/else and while. If those use a block for the body, then they don't require a semicolon.

So, if nested braceless control structures end, they all end in the same place!

I'll not fix your code, but I'll comment it.

01 sub standarization { # was standarization(void) 02 my(i,j,k); 03 for (i=1; i<=10; i++) # where does "for" end? 04 if (d[i][0]!=0) # where does "if" end? 05 for (k=1; k<24; k++) 06 { 07 d[0][k] += d[i][k]; 08 d[i][k] /= d[i][0]; 09 } # end of "for" statement on line 05 # end of "if" on line 04 # end of "for" on line 03 10 11 for (i=9; i<=18; i++) # where does "for" end? 12 if (psb[i][0]!=0) # where does "if" end? 13 for (k=11; k<=BUST; k++) 14 { # new 15 psb[i][k] /= psb[i][0]; 16 } # new # end of "if" on line 12 # end of "for" on line 11 17 18 for (j=1; j<=10; j++) # where does "for" end? 19 if (s[j][0][0]!=0) { 20 for (i=12; i<=18; i++) { 21 if (s[j][i][0]!=0) # where does "if" end? 22 for (k=12; k<=BUST; k++) 23 { # new 24 s[j][i][k] /= s[j][i][0]; 25 } # new # end of "if" on line 21 26 27 if (s[j+10][i][0]!=0) # where does "if" end? 28 for (k=12; k<=BUST; k++) 29 { # new 30 s[j+10][i][k] /= s[j+10][i][0]; 31 } # new # end of "if" on line 27 32 s[j][i][0] /= s[j][0][0]; 33 s[j][i][1] /= s[j][0][0]; 34 s[j+10][i][0] /= s[j][0][0]; 35 s[j+10][i][1] /= s[j][0][0]; 36 } # end "for" line 20 37 38 for (k=17; k<=BUST; k++) { 39 s[j][0][k] /= s[j][0][0]; 40 s[j+10][0][k] /= s[j][0][0]; 41 } 42 } # end of "if" line 19 43 } # end of sub

You'll probably agree by now, that Perl's enforcement of use of braces for control structures, was a sane decision!


In reply to Re: Convert loop and if constructs from C to Perl by bart
in thread Convert loop and if constructs from C to Perl by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.