Message Boards Message Boards

0
|
5164 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Code for a variable number of nested For functions?

Posted 4 years ago

Can code be written that specifies how many For statements will be nested as a variable x increases?

If x=3, we would nest three For statements with indices: istart, iend; jstart, jend, and kstart, kend.

If x=10, there would be 10 such terms all with different start and stop indices.

POSTED BY: Douglas Youvan
5 Replies
Posted 4 years ago

@Douglas: You can see an example of code that produces code here.

@Hans: That is what I would call an elegant solution.

POSTED BY: Mike Besso

Thank you all. This will take me a while to digest.

POSTED BY: Douglas Youvan
POSTED BY: Hans Dolhaine

Thank you, Mike. The problem I am working on was solved years ago by what one might consider an elegant method. However, now that I think about it more, I would actually be interested in seeing some Mathematica code that writes Mathematica code.

POSTED BY: Douglas Youvan
Posted 4 years ago

Douglas:

I am sure a solution exists for this, as a last resort, you could write a function that generates the code and then executes the code. But, there is probably a more elegant solution.

Could you explain your use case? That additional information will help the community help you.

Have a great weekend.

POSTED BY: Mike Besso
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract