So what I am trying to do is to create a list of terms that will be plotted on separate graphs in a for loop. What I want to do is create a table of values and for each i there is a specific value. So basically I want to do this:
For[
variables in a table {i=1,i=2,i=3,i=4}
Plot some function with value associated to value in the table for this i value until you reach the last i value given in the list
No! The code is completely OK and does what it does. Again: For does not store nor print any values! It just executes the loop, but does not print or return the results.
Remark:
For can return a single value by using Return, but calling Return aborts the loop immediately.
Use Print to show the output of the body for each iteration
Use Sow and Reap to save any data
Let me repeat, try to stay away from For if you can replace it with Do.
Thank you, Sander! So, we can conclude that the For[] loop is a function that doesn’t have side effects as the For[] loop in the other procedural languages. Do I do the correct conclusion?
It can have side effects (Print, Sow…) It just does not store/print the results of the body. Use Table to do that.
For loop very similar in behavior like C (or any other language for that matter). It just executes the loop but does not store anything without an explicit print (printf) statement.
See Matlab, C, (visual) basic, python, … none of them stores the results of the body for each iteration. In all those languages you need an explicit print statement to see the results. Same for Mathematica
I found why I misunderstood this example. I have thought that the Plot[] function works exactly as the Print[] function! So, the problem was not in the For[] loop, but in the effect which have the Plot[] function. It must be supplemented by Print[] to have the needed result!