Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Printing results if certain conditions are met in Mathematica

  1. Jun 11, 2012 #1
    Hello everyone,

    I have for loop in Mathematica. After every step Mathematica has new results calculated. I want to see only some results, those who met certain conditions, not results from all steps. Say, I have 10000 steps and I don't need all 10000 results, but only those that met certain conditions. There are at least two or more conditions to be met. How can I tell Mathematica to print only those results?

    So I want to tell this to Mathematic ain a for loop:

    If a is true and b is true or c is true and d is true, then print blablabla, else do nothing.
     
  2. jcsd
  3. Jun 12, 2012 #2
    In[1]:=For[i=1,i<100,i++,
    (*doing stuff*)
    If[Or[And[i>25,i<30],And[Mod[i,7]==3,Mod[i,11]==8]],Print]
    (*doing more stuff*)
    ]

    From In[1]:=26
    From In[1]:=27
    From In[1]:=28
    From In[1]:=29
    From In[1]:=52
     
    Last edited: Jun 12, 2012
  4. Jun 12, 2012 #3
    Thank you very much for your kind replay :).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Printing results if certain conditions are met in Mathematica
Loading...