Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a simple For[] loop:

For[rPos = 0, rPos<=(2 N[Pi]), rPos += radiusInc,
    zPotential = 0;
    xPos = rDistance Cos[rPos];
    yPos = rDistance Sin[rPos];
    zPos = planeDepth;
    AppendTo[zField, {xPos,yPos, zPos, zPotential}];     

The only line of the body that is executed is:

zPotential = 0;

At the end, zField has zero items.

If I set a breakpoint on the second or third line it never hit.

I know that For[] and Do[] loops are discouraged, but I do not see the cause of this problem.

share|improve this question
Please post complete code that can be simply copied and pasted for testing. It's impossible to know what the problem is in your case because several definitions are missing. Please see sscce.org for useful guidelines. –  Szabolcs Jun 17 at 19:50
Please do not cross post. I answered your question here community.wolfram.com/dashboard it is waste of people time. if you want to cross post, mention in each post where you posted as well, so people do not duplicate things. –  Nasser Jun 17 at 20:08
@Nasser so what now? :P –  Kuba Jun 19 at 8:27
add comment

1 Answer 1

I post this to just illustrate alternative to For loop:

rDistance = 5.4;
radiusInc = Pi/20.;
zField = rDistance {Cos[#], Sin[#], 0} & /@ Range[0, 2 Pi, Pi/20];

enter image description here

share|improve this answer
Interesting alternative! Is the performance better than the For[] loop? –  user1585715 Jun 18 at 19:34
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.