Re: Stopping a For loop
- To: mathgroup at smc.vnet.net
- Subject: [mg43098] Re: [mg43083] Stopping a For loop
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Tue, 12 Aug 2003 04:43:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On Monday, August 11, 2003, at 02:16 AM, Miguel Cruz wrote: > I am trying to break the For loop when a is larger than h: > > testFOR[h_]:= > For[s=0, s<10; If[a-h>0, Break[]] ,s++, > a=y6[s]-sin[Pi/2-y3[s]]*y1[s]*y1[s]/rhop*y2[s]) /.solution; > Print[s,a] > ] > > My problem is that the loop never breaks unless in the If condition I > put the iterator s. Put the Break after the assignment to a. testFOR[h_]:= For[s=0, s<10 ,s++, a=y6[s]-sin[Pi/2-y3[s]]*y1[s]*y1[s]/rhop*y2[s]) /.solution; Print[s,a];If[a-h>0, Break[]]] Mathematica expects a True or False value for the test expression, your compound expression does not return one so the loop is never started. If you use Trace this is easy to see. Regards, Ssezi