I have a Do loop running which, for some values will become complex, and I want to make it so for these situations, we take the negative root and for others the positive root. In this scenario, I've simplified what I actually have and chose to look at the case where I need it to take the negative root(adsbygoogle = window.adsbygoogle || []).push({});

I can't seem to get the syntax right here, and if I print a table with the results it's as if the If is just being ignored.Code (Text):

Do[e[o] = 0.5 + o, {o, 0, 10}]

Do[If[Element[x[n, o] = (e[o] - n)^(1/2), Complexes], -[x[n, o]],

x[n, o]], {n, -10, 10}, {o, -10, 10}]

Ideally, this would be the best approach for my problem as my actual code is quite complex and values in the Do loops are called upon, so I fear any other method will cause grief elsewhere.

Thanks for any help!

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Mathematica If statement inside a Do loop

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads - statement inside loop | Date |
---|---|

Simplify Matlab for/if statements further | Feb 25, 2015 |

Nested if statements in MATLAB | Sep 25, 2013 |

Mathematica: Duplex Printing from button inside DialogNotebook on Mac | Jun 19, 2013 |

MATLAB For Statement [ HELP ] | Jul 29, 2012 |

Matlab if statements and extracting rows of data | Oct 1, 2011 |

**Physics Forums - The Fusion of Science and Community**