Re: If statement inside Do loop

*To*: mathgroup at smc.vnet.net*Subject*: [mg4651] Re: If statement inside Do loop*From*: wagner at motel6.cs.colorado.edu (Dave Wagner)*Date*: Thu, 22 Aug 1996 03:55:06 -0400*Organization*: University of Colorado, Boulder*Sender*: owner-wri-mathgroup at wolfram.com

In article <4v166s$f8k at ralph.vnet.net>, Heather Mary Hauser <gt1824a at prism.gatech.edu> wrote: > >I apologize for the length of this post, but the problem is driving me crazy. >Mathematica ignores the If statement inside this Do loop. The program runs >fine, no error messages, but it doesn't do what I want it to. Any help on why >this is would be greatly appreciated. >relevant part of program follows: > >Do[ > <snip> Here's your problem: > lstrl = First[rlist]; lstim = Firts[imlist]; You've mispelled "First". Now lstim and every value obtained from it will contain the expression Firts[imlist], which doesn't evaluate. > comre = N[Evaluate[lstrl*recon]]; > comim = N[Evaluate[lstim*imcon]]; > If[comre <= 0 && comim <= 0, Print["instability near", omi], > Print["no"]]; comim is not a numeric expression, hence the expression comim <= 0 does not evaluate. Therefore the If does not evaluate to either of the alternatives. What you should do in the future to find problems like this is use the four-parameter form of If: If[test, true clause, false clause, neither clause] After noticing that test is neither true nor false, you can then insert Print statements to narrow down the problem. In this case, the problem was easy to find by inspection. By the way, I haven't run your code, so I don't know if this is the only problem with it. Dave Wagner Principia Consulting (303) 786-8371 dbwagner at princon.com http://www.princon.com/princon ==== [MESSAGE SEPARATOR] ====