Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!newsfeed.news.ucla.edu!nrc-news.nrc.ca!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: go to statment in matlab
Date: Sat, 18 Aug 2007 06:44:44 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 58
Message-ID: <fa64gs$d9m$1@canopus.cc.umanitoba.ca>
References: <f9f08u$qqp$1@fred.mathworks.com> <f9f180$f8j$1@fred.mathworks.com> <f9fm8n$7g1$1@canopus.cc.umanitoba.ca> <fa61hd$so$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1187419484 13622 192.70.172.160 (18 Aug 2007 06:44:44 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Sat, 18 Aug 2007 06:44:44 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:424387


In article <fa61hd$so$1@fred.mathworks.com>,
huda nawaf <halmamory@yahoo.com> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in 
>message <f9fm8n$7g1$1@canopus.cc.umanitoba.ca>...
>> In article <f9f180$f8j$1@fred.mathworks.com>, us  
><us@neurol.unizh.ch> wrote:
>> >huda nawaf:
>> ><SNIP stubborn...

>> >> how I can use go to statment in matlab?

>> >the <goto> statement does not exist in ML...

>> *Some* uses of goto can be replaced by try/catch blocks 
>> catching custom error() conditions. 

>hi us,

'us' was the person who mentioned that goto does not exist.
The person you are replying to, who mentioned try and catch,
is 'Walter'.

>please I don't know how can use it (try and catch)
>please give me example .


%code as it would be if GO TO existed:
for K = 1:N
  do_something;
  if some_variable == 0, GO TO Opps0, end;
  do_something_more;
end
return

Opps0:
sprintf('Zero encountered at iteration %d\n', K);
return


%code using try/catch instead:
try
  for K =1:N
    do_something;
    if some_variable == 0 then error('Opps0') end;
    do_something_more;
  end
  return
catch
  if lasterror == 'Opps0'
    sprintf('Zero encountered at iteration %d\n', K);
    return
  else
    rethrow(lasterror)
  end
end
-- 
   "No one has the right to destroy another person's belief by
   demanding empirical evidence."              -- Ann Landers