Hello,(adsbygoogle = window.adsbygoogle || []).push({});

I am a novice in Mathematica, but insisting to learn it. I would appreciate help in solving the following problem:

(*a=1;Which[a==1,x,a==2,b]*)

list := List[1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 32, 10]

For[i = 1, i < 4, i++,

a = list[];

Print[a];

Print[list[]];

Which[a == 1611, x, a == 1612, y];

Print[%]]

When I run the code, I get the following result:

1611

1611

Null

1612

1612

Null

1613

1613

Null

While I think I am faithfully mimicking the Mathematica "Which statement" quoted above, it seems including the "Which" statement in the "For" loop does not make work as intended. Is this right? If not, please point out my mistake.

Best Regards

**Physics Forums | Science Articles, Homework Help, Discussion**

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

# Mathematica Help with "Which[] in a For loop using Mathematica

Tags:

Loading...

Similar Threads for Help loop using |
---|

Help with Excel graph please |

Mathematica Looping through vectorized functions for a piecewise solution |

MATLAB MATLab: Not enough inputs for nlinfit |

MATLAB Help needed to fix a matlab code |

LaTeX Help with page dimensions in latex |

**Physics Forums | Science Articles, Homework Help, Discussion**