       Problem with If statement in a Do or a While loop

• To: mathgroup at smc.vnet.net
• Subject: [mg39437] Problem with If statement in a Do or a While loop
• From: A.Reinstaller at MERIT.unimaas.nl
• Date: Sat, 15 Feb 2003 01:42:08 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```There is a problem I continue to have, perhaps one knows what's wrong.  I
try to check the values generated by an interpolating function. I do so by
using a Do loop in which I ask whether the function has reached some value
within a small intervall and if so to write the time tag of the first hit
out. Now, when running the program it does not step into the IF evaluations.
I have added an else branch to be sure that even if the condition was not
true something would be written out. I have also checked whether the values
of the interpolating function are correctly extracted as well as whether
they were really lying in the intervall asked for in the IF statement. In
top of that I varied the stepsize to a minimal and increased the margins of
the intervall. I used also a While instead of a Do loop. But in any case
neither the THEN nor the ELSE branch "fired", telling me that the IF
statement is not checked. WHY????

> Is there some restriction for the use of IF clauses in loops in
> Mathematica? Otherwise I could not explain why nothing happens. I checked
> in the manual but nothing was mentioned.
>
> Thanks for your forthcoming help. Andreas
>
> Here is the code:
>
> solutionIncome=
> NDSolve[Join[veblen07,IvaluesIncome],{x1,x2,y1,y2,py},{t,0,Tmax}];
>
> 	S={(q1*y1[t]+q2*y2[t])/.solutionIncome/.t->Tmax};
> 	c10=S*0.01; c90=S*0.9;
> 	t10=0;t90=0; \[CapitalDelta]t=0;
> 	tol=0.1; stept=Tmax*0.0001;
>
>   	Do[ {
> 		y=(q1*y1[t]+q2*y2[t])/.solutionIncome/.t->\[Theta];
>     		If[ (   (y>(c10-(c10*tol) )|| y<(c10+(c10*tol)) ) && t10 ==0
> ) ,( t10=\[Theta]; Print["t10 found"]; Continue[] ) , (Print["t10 not
> found"]; Continue[])   ];
>     		If[ (   ( y>(c90-(c90*tol)) || y<(c90+(c90*tol)) ) && t90
> ==0   ) ,(t90=\[Theta]; Print["t90 found"]; Continue[]), (Print["t90 not
> found"]; Continue[])  ];
>     		If[ (t10>0) && (t90>0),(\[CapitalDelta]t=t90-t10;
> Continue[]) ];
> 	        },
>                  {\[Theta],0,Tmax,stept}];
>
>
>

```

• Prev by Date: Re: OT:Alternatives for Mathtype w OS X & WORD/Endnote?
• Next by Date: Plotting problem
• Previous by thread: Guilloche patterns --- slightly off group topic
• Next by thread: Re: Problem with If statement in a Do or a While loop