For Loop Problem in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Loop Mathematica
Click For Summary

Discussion Overview

The discussion revolves around executing multiline code within a for loop in Mathematica. Participants explore syntax issues and best practices for structuring code in this programming environment.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant seeks guidance on executing multiline code for each iteration of a for loop.
  • Another participant provides a syntax example using the For loop structure in Mathematica.
  • A later reply acknowledges a mistake in using ',' instead of ';' and notes that correcting this improves code execution.
  • Another participant confirms that using ';' allows for creating compound statements, suggesting it is a useful technique in other contexts as well.

Areas of Agreement / Disagreement

Participants appear to agree on the importance of correct syntax in Mathematica for executing multiline code, but the discussion does not delve into broader implications or alternative methods.

Contextual Notes

The discussion does not address potential limitations or assumptions regarding the specific context of the code or the variable 'n'.

EngWiPy
Messages
1,361
Reaction score
61
Hello,
I want to execute a multiline code for each value of the for loop. How can I do that?
Regards
 
Physics news on Phys.org
For[
i = 0, i < n, i++,
line1;
line2;
line3
]
 
DaleSpam said:
For[
i = 0, i < n, i++,
line1;
line2;
line3
]

Thanks DaleSpam. I used ',' instead of ';', which was not accepted by Mathematica. This saves a lot of effort.
Best regards
 
No problem. You can always use ; to make a compound statement, so it is a general trick that helps elsewhere too.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K