<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, do loop ...on error goto?</title>
    <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Sat, 13 Jun 2026 20:40:14 GMT</lastBuildDate>
    <pubDate>Sat, 13 Jun 2026 20:40:14 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, do loop ...on error goto?</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, do loop ...on error goto?</title>
      <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto</link>
    </image>
    <item>
      <title>try..catch</title>
      <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto?ref=Feed:MaplePrimes:do loop ...on error goto?:Comments#answer130029</link>
      <itunes:summary>&lt;p&gt;Do you want something like this?&lt;/p&gt;
&lt;pre&gt;SPV := proc (values::list, b::integer)
local a, N, const, value, res;
  N := nops(values);
  const := convert([seq(x || i, i = 1 .. N)], `+`) &amp;lt;= b;
  value := convert([seq(x || i*values[i], i = 1 .. N)], `+`);
  for a to 100 do
    res:='res'; # wasn't sure whether you wanted final result. if not, get rid of res.
    try
      res := Optimization:-LPSolve(value, {value = a, const}, assume = {nonnegint},
                                  depthlimit = 200, maximize);
    catch "no feasible integer point found":
      return a+1;
    catch "no feasible point found for LP subproblem":
      return a+1;
    catch: # all other errors
      error; # rethrow the error
    end try;
  end do;
  NULL;
end proc:

SPV([1, 2, 5, 7], 13);

                               89

SPV([1, 4, 12, 21], 5);

                               73

SPV([1, 2, 7, 12, 50], 5);

                               42

SPV([1, 2, 5, 20], 7);

                               79
&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;Do you want something like this?&lt;/p&gt;
&lt;pre&gt;SPV := proc (values::list, b::integer)
local a, N, const, value, res;
  N := nops(values);
  const := convert([seq(x || i, i = 1 .. N)], `+`) &amp;lt;= b;
  value := convert([seq(x || i*values[i], i = 1 .. N)], `+`);
  for a to 100 do
    res:='res'; # wasn't sure whether you wanted final result. if not, get rid of res.
    try
      res := Optimization:-LPSolve(value, {value = a, const}, assume = {nonnegint},
                                  depthlimit = 200, maximize);
    catch "no feasible integer point found":
      return a+1;
    catch "no feasible point found for LP subproblem":
      return a+1;
    catch: # all other errors
      error; # rethrow the error
    end try;
  end do;
  NULL;
end proc:

SPV([1, 2, 5, 7], 13);

                               89

SPV([1, 4, 12, 21], 5);

                               73

SPV([1, 2, 7, 12, 50], 5);

                               42

SPV([1, 2, 5, 20], 7);

                               79
&lt;/pre&gt;</description>
      <guid>130029</guid>
      <pubDate>Wed, 25 Jan 2012 11:32:01 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>another one - try..catch</title>
      <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto?ref=Feed:MaplePrimes:do loop ...on error goto?:Comments#comment130181</link>
      <itunes:summary>&lt;p&gt;thx Pagan, it works well.&lt;/p&gt;
&lt;p&gt;I have another, related problem. this time it needs to stay looping while errors are generated, to find the one or two "real" answers. i hope the worksheet is self explanatary&lt;/p&gt;
&lt;p&gt;&lt;a href="/view.aspx?sf=130181/429717/subset_sum_proble.mw"&gt;subset_sum_proble.mw&lt;/a&gt;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;thx Pagan, it works well.&lt;/p&gt;
&lt;p&gt;I have another, related problem. this time it needs to stay looping while errors are generated, to find the one or two "real" answers. i hope the worksheet is self explanatary&lt;/p&gt;
&lt;p&gt;&lt;a href="/view.aspx?sf=130181/429717/subset_sum_proble.mw"&gt;subset_sum_proble.mw&lt;/a&gt;&lt;/p&gt;</description>
      <guid>130181</guid>
      <pubDate>Mon, 30 Jan 2012 09:44:39 Z</pubDate>
      <itunes:author>brian bovril</itunes:author>
      <author>brian bovril</author>
    </item>
    <item>
      <title>another one</title>
      <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto?ref=Feed:MaplePrimes:do loop ...on error goto?:Comments#comment130184</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto#comment130181"&gt;@brian bovril&lt;/a&gt; If it survives the try..catch then it augments the table of successes. If it hits an acceptable error (no solution found) then it advances to the next loop iteration. If it hits any other error then it rethrows the error so that the procedure can itself stop with that error. And it returns a sequence of the table entries.&lt;/p&gt;
&lt;pre&gt;restart:

SSP := proc(values::list)
local a, N, const, sumv, res, allsols, x;
  N := nops(values);
  const := add(x || i, i = 1 .. N);
  sumv := add(x || i*values[i], i = 1 .. N);
  for a to N do
    try
      res := Optimization:-LPSolve(sumv, {const = a, sumv = 0},
                                   assume = {binary}, depthlimit = 200);
    catch "no feasible integer point found":
      next;
    catch "no feasible point found for LP subproblem":
      next;
    catch: error;
    end try;
    allsols[a]:=res;
  end do;
  return seq([x,allsols[x]], x in indices(allsols,nolist));
end proc:

SSP([-7, -3, -2, -5, 5]);

      [2, [0, [x1 = 0, x2 = 0, x3 = 0, x4 = 1, x5 = 1]]], 

        [3, [0, [x1 = 0, x2 = 1, x3 = 1, x4 = 0, x5 = 1]]]

SSP([-7, -3, -2, 5, 8]);

       [3, [0, [x1 = 0, x2 = 1, x3 = 1, x4 = 1, x5 = 0]]]
&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto#comment130181"&gt;@brian bovril&lt;/a&gt; If it survives the try..catch then it augments the table of successes. If it hits an acceptable error (no solution found) then it advances to the next loop iteration. If it hits any other error then it rethrows the error so that the procedure can itself stop with that error. And it returns a sequence of the table entries.&lt;/p&gt;
&lt;pre&gt;restart:

SSP := proc(values::list)
local a, N, const, sumv, res, allsols, x;
  N := nops(values);
  const := add(x || i, i = 1 .. N);
  sumv := add(x || i*values[i], i = 1 .. N);
  for a to N do
    try
      res := Optimization:-LPSolve(sumv, {const = a, sumv = 0},
                                   assume = {binary}, depthlimit = 200);
    catch "no feasible integer point found":
      next;
    catch "no feasible point found for LP subproblem":
      next;
    catch: error;
    end try;
    allsols[a]:=res;
  end do;
  return seq([x,allsols[x]], x in indices(allsols,nolist));
end proc:

SSP([-7, -3, -2, -5, 5]);

      [2, [0, [x1 = 0, x2 = 0, x3 = 0, x4 = 1, x5 = 1]]], 

        [3, [0, [x1 = 0, x2 = 1, x3 = 1, x4 = 0, x5 = 1]]]

SSP([-7, -3, -2, 5, 8]);

       [3, [0, [x1 = 0, x2 = 1, x3 = 1, x4 = 1, x5 = 0]]]
&lt;/pre&gt;</description>
      <guid>130184</guid>
      <pubDate>Mon, 30 Jan 2012 10:47:56 Z</pubDate>
      <itunes:author>pagan</itunes:author>
      <author>pagan</author>
    </item>
    <item>
      <title>try-catch</title>
      <link>http://www.mapleprimes.com/questions/130026-Do-Loop-on-Error-Goto?ref=Feed:MaplePrimes:do loop ...on error goto?:Comments#comment130297</link>
      <itunes:summary>&lt;p&gt;thx Pagan, works well&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;thx Pagan, works well&lt;/p&gt;</description>
      <guid>130297</guid>
      <pubDate>Fri, 03 Feb 2012 10:12:08 Z</pubDate>
      <itunes:author>brian bovril</itunes:author>
      <author>brian bovril</author>
    </item>
  </channel>
</rss>