Now that others have explained the C-style loop structure that you intended to use, it might help to know that Perl has another kind of for-loop structure:
for ( list, of, items ) { ...}
By using commas in your original code, that is the type of loop you created. Your first attempt also demonstrates how this "for (list...)" structure evaluates (creates) the entire list before doing the first iteration. In effect, the OP code is sort of equivalent to:
$i = 500;
$i = 900;
$i += 100;
for ( $i, $i, $i ) {
....
}
In this sort of for loop (with no explicit loop variable given, as in
for my $x (list...)), at each iteration, the special global variable "$_" is set to the given value in the list, so the body of the loop would have done the same thing as the OP code if written as follows:
my $theta = $T * (( 1013 / $_ ) ** ( 287/1004 ));
push ( @press, $_ );
push ( @thetas, $theta );
(updated to fix grammar mistake, and to add more info in last paragraph)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.