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

closed as off-topic by Michael E2, Öskå, ubpdqn, Simon Woods, RunnyKine Aug 17 at 15:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Michael E2, Öskå, ubpdqn, Simon Woods, RunnyKine
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
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
8  
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
    
@Nasser Could you post the link to your answer then, and maybe edit it into the post? –  Pickett Aug 17 at 10:32
    
I'm voting to close because the question is incomplete. Also, it has been answered on the Wolfram Community site. –  Michael E2 Aug 17 at 12:23

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];
ListLinePlot[zField]

enter image description here

share|improve this answer
    
Interesting alternative! Is the performance better than the For[] loop? –  user1585715 Jun 18 at 19:34
    
@user1585715 Yes. –  Michael E2 Aug 17 at 12:05

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