<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Another perl question in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136705#M154231</link>
    <description>If i'd have got the code to run, i may have saved a whole load of questions&lt;BR /&gt;&lt;BR /&gt;here's how i got it to explain itself&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;for ($i=0; $i&amp;lt;100; $i++ ) {&lt;BR /&gt;print "This is the outerloop and has value $i\n";&lt;BR /&gt;        for ($j=0; $j&amp;lt;100; $j++) {&lt;BR /&gt;        print "This is the inner loop and has value $j\n";&lt;BR /&gt;                if ( $i * $j == 140) {&lt;BR /&gt;                print "The Product of $i and $j is 140\n";&lt;BR /&gt;                last ;&lt;BR /&gt;        }&lt;BR /&gt;        }&lt;BR /&gt;      }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;BR /&gt;&lt;BR /&gt;Steve</description>
    <pubDate>Thu, 04 Dec 2003 19:38:30 GMT</pubDate>
    <dc:creator>steven Burgess_2</dc:creator>
    <dc:date>2003-12-04T19:38:30Z</dc:date>
    <item>
      <title>Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136693#M154219</link>
      <description>Hi everyone&lt;BR /&gt;&lt;BR /&gt;I understand that the 'last' statement will exit the loop if the defined condition is met.&lt;BR /&gt;&lt;BR /&gt;If you have multiple nested loops then 'last' will exit the innermost loop, again when the defined condition is met&lt;BR /&gt;&lt;BR /&gt;Some of you may read the next statement and understand exactly what is meant. I however am struggling and would be grateful if anyone could expand on the authors comments. I'm going to type it, exactly how it's written. I have put my queries within the paragraph in brackets&lt;BR /&gt;&lt;BR /&gt;The set of nested loops in fig 3.2 finds all the whole numbers less than 100 whose products are 140-2 and 70,4 and 35,(it only prints if ==140, what does he mean ?) and so on - rather inefficently. The point to note here is the 'last' statement. When the product is found (140), the result is printed and the inner loop is exited (understood). The outer loop continues executing and reruns the inner loop (does that mean the next check will be the previous value of $j and the next incremented value of $i)&lt;BR /&gt;&lt;BR /&gt;fig 3.2&lt;BR /&gt;&lt;BR /&gt;/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;for ($i=0; $i&amp;lt;100; $i++ ) {&lt;BR /&gt;        for ($j=0; $j&amp;lt;100; $j++) {&lt;BR /&gt;                if ( $i * $j == 140) {&lt;BR /&gt;                print "The Product of $i and $j is 140\n";&lt;BR /&gt;                last ;&lt;BR /&gt;}&lt;BR /&gt;        }&lt;BR /&gt;      }&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Dec 2003 18:30:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136693#M154219</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T18:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136694#M154220</link>
      <description>When i=1 and j=140, the print statment will execute, and the last statement will exit the inner loop.  i will be incremented to 2 and then the inner loop will begin again with j=0.  When j=70, the print and last statements will again be executed, sending the process back to the outer loop to increment i to 3.  etc., etc...</description>
      <pubDate>Thu, 04 Dec 2003 18:45:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136694#M154220</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-12-04T18:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136695#M154221</link>
      <description>&amp;gt; products are 140-2 and 70,4 and 35,&lt;BR /&gt;&amp;gt;(it only prints if ==140, what does he  mean ?) &lt;BR /&gt;&lt;BR /&gt;Yes, and the first solution found is 2*70, the next 4*35.&lt;BR /&gt;You have run the program right?! (See below)&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The outer loop continues executing and reruns the inner loop &lt;BR /&gt;&lt;BR /&gt;Let's say i is 2 in the outerloop.&lt;BR /&gt;The innerloop increments J from 0 to 70 and then it recognizes a solution. So it prints and issues last. The inner (j) loop is now done. j does not become 71 this time around. The outerloop gets control, finds no more statements and goes to loop control to increment i to 3. As first (and only) statement in the new outer loop iteration it restarts the inner loop incrementing j from 0 to 100... without ever finding a solution. It drops through to the outer, i is made 4, the inner starts j again at 0 and finds the next solution when j becomes 35... and so on.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;The Product of 2 and 70 is 140&lt;BR /&gt;The Product of 4 and 35 is 140&lt;BR /&gt;The Product of 5 and 28 is 140&lt;BR /&gt;The Product of 7 and 20 is 140&lt;BR /&gt;The Product of 10 and 14 is 140&lt;BR /&gt;The Product of 14 and 10 is 140&lt;BR /&gt;The Product of 20 and 7 is 140&lt;BR /&gt;The Product of 28 and 5 is 140&lt;BR /&gt;The Product of 35 and 4 is 140&lt;BR /&gt;The Product of 70 and 2 is 140&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Dec 2003 18:47:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136695#M154221</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2003-12-04T18:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136696#M154222</link>
      <description>ooops...neither i nor j will ever be allowed to reach the value of 140.  So, while the logic of my last statement is still true, the actual first execution of the print and last statements will not occur until {i,j} = {2,70}</description>
      <pubDate>Thu, 04 Dec 2003 18:49:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136696#M154222</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-12-04T18:49:53Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136697#M154223</link>
      <description>Hi, thanks for the replies&lt;BR /&gt;&lt;BR /&gt;reading now, still struggling!&lt;BR /&gt;&lt;BR /&gt;I tried to run the loop to see exactly what it's doing but it didn't do anything!! . I have it exactly as above&lt;BR /&gt;&lt;BR /&gt;How does the loop control the increment of each variable ?&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Dec 2003 19:05:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136697#M154223</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136698#M154224</link>
      <description>nearly there&lt;BR /&gt;&lt;BR /&gt;so the inner loop is incremented whilst the outer loop stays at a fixed value until the product is met ?&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Dec 2003 19:09:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136698#M154224</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136699#M154225</link>
      <description>Precisely!  You got it.</description>
      <pubDate>Thu, 04 Dec 2003 19:15:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136699#M154225</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-12-04T19:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136700#M154226</link>
      <description>Hein&lt;BR /&gt;&lt;BR /&gt;I may embarass myself here&lt;BR /&gt;&lt;BR /&gt;How have you got the programme to run ?&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Dec 2003 19:21:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136700#M154226</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136701#M154227</link>
      <description>A good analogy just occurred to me...think of the loops as if they represented the hour and minute hands of a clock.  The outer loop is equivalent to the hour hand, while the inner loop represents the minute hand.  The minute hand (inner loop) will be incremented 60 times before the hour hand (outer loop) is incremented once.  Once the hour hand is incremented, the minute hand is "reset" to its starting position and must increment another 60 times before the hour hand is once again incremented....</description>
      <pubDate>Thu, 04 Dec 2003 19:23:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136701#M154227</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-12-04T19:23:45Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136702#M154228</link>
      <description>create a file called test.pl....&lt;BR /&gt;&lt;BR /&gt;insert the following...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;for ($i=0; $i&amp;lt;100; $i++ ) {&lt;BR /&gt;for ($j=0; $j&amp;lt;100; $j++) {&lt;BR /&gt;if ( $i * $j == 140) {&lt;BR /&gt;print "The Product of $i and $j is 140\n";&lt;BR /&gt;last ;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;save it...and then...&lt;BR /&gt;&lt;BR /&gt;$ perl test.pl&lt;BR /&gt;The Product of 2 and 70 is 140&lt;BR /&gt;The Product of 4 and 35 is 140&lt;BR /&gt;The Product of 5 and 28 is 140&lt;BR /&gt;The Product of 7 and 20 is 140&lt;BR /&gt;The Product of 10 and 14 is 140&lt;BR /&gt;The Product of 14 and 10 is 140&lt;BR /&gt;The Product of 20 and 7 is 140&lt;BR /&gt;The Product of 28 and 5 is 140&lt;BR /&gt;The Product of 35 and 4 is 140&lt;BR /&gt;The Product of 70 and 2 is 140&lt;BR /&gt;&lt;BR /&gt;$ perl test.pl&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Dec 2003 19:25:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136702#M154228</guid>
      <dc:creator>James A. Donovan</dc:creator>
      <dc:date>2003-12-04T19:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136703#M154229</link>
      <description>thats a pretty good analogy, it's a pity the text doesn't explain exactly how the loops work and just presume you know, or is that just because i'm a little slow ?&lt;BR /&gt;&lt;BR /&gt;tehe&lt;BR /&gt;&lt;BR /&gt;Thanks everyone&lt;BR /&gt;&lt;BR /&gt;more questions to come , no doubt&lt;BR /&gt;&lt;BR /&gt;steve</description>
      <pubDate>Thu, 04 Dec 2003 19:26:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136703#M154229</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136704#M154230</link>
      <description>i'm not going to tell you where the deliberate mistake was&lt;BR /&gt;&lt;BR /&gt;it didn't error though when i did a ./prog.pl but only when i did perl prog.pl which gave me a clue&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Steve&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Dec 2003 19:31:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136704#M154230</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:31:18Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136705#M154231</link>
      <description>If i'd have got the code to run, i may have saved a whole load of questions&lt;BR /&gt;&lt;BR /&gt;here's how i got it to explain itself&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;for ($i=0; $i&amp;lt;100; $i++ ) {&lt;BR /&gt;print "This is the outerloop and has value $i\n";&lt;BR /&gt;        for ($j=0; $j&amp;lt;100; $j++) {&lt;BR /&gt;        print "This is the inner loop and has value $j\n";&lt;BR /&gt;                if ( $i * $j == 140) {&lt;BR /&gt;                print "The Product of $i and $j is 140\n";&lt;BR /&gt;                last ;&lt;BR /&gt;        }&lt;BR /&gt;        }&lt;BR /&gt;      }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 04 Dec 2003 19:38:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136705#M154231</guid>
      <dc:creator>steven Burgess_2</dc:creator>
      <dc:date>2003-12-04T19:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Another perl question</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136706#M154232</link>
      <description>For something completely different, what you are doing is programming C in perl, where perl has much more beautiful ways to express such loops:&lt;BR /&gt;&lt;BR /&gt;foreach my $i (0..140) {&lt;BR /&gt; foreach my $j (0..140) {&lt;BR /&gt;  $i * $j == 140 or next;&lt;BR /&gt;  print "The product of $i and $j is 140\n;&lt;BR /&gt;  last;&lt;BR /&gt;  }&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Fri, 05 Dec 2003 02:29:05 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/another-perl-question/m-p/3136706#M154232</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2003-12-05T02:29:05Z</dc:date>
    </item>
  </channel>
</rss>

