comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » BREAK statement
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: BREAK statement [message #91344 is a reply to message #91343] Wed, 01 July 2015 08:55 Go to previous messageGo to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Wednesday, July 1, 2015 at 5:41:35 PM UTC+2, g.na...@gmail.com wrote:
> Hi I typed the following:
>
> A = sqrt(Ax^2 + Ay^2)
>
> nozero = where(A ne 0, cnt)
> if cnt eq 0 then break
>
> I got the following error:
> BREAK must be enclosed within a loop (FOR, WHILE, REPEAT), CASE, or SWITCH statement.
>
> The error is very clear. I am not sure if the following is equivalent
>
> A = sqrt(Ax^2 + Ay^2)
>
> nozero = where(A ne 0, cnt)
> if cnt eq 0 then return
>
> Using the return instead of break because that part of code does not enclosed within a loop. If not so, can anyone suggest a statement doing the same thing as BREAK without being enclosed within a loop?

Break and Return are simply different.
From the help

Break: exits a loop (as said in the error code)
Return: causes the program context to revert to the next-higher program level

In other words:

pro runTest
print, 'start test'
testBreakReturn
print, 'end test'
end

Pro testBreakReturn
for i=0,10 do begin
print, 'counting ',i
if i eq 5 then break
endfor
print, "I'm out of the for loop!"
print, 'Now I will call the return statement'
return
print, 'this line will not be executed becuase the return makes me return to the previous pro!'
end

I hope it is clear.

Look up:
http://www.exelisvis.com/docs/BREAK.html
http://www.exelisvis.com/docs/RETURN.html

Cheers,
Helder
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: function graphic question
Next Topic: plotting a sub field image..

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:11:52 PDT 2025

Total time taken to generate the page: 0.00462 seconds