ztar[n_] := Module[{xlist, ylist, points, plots}, plots = {}; xlist = {1}; ylist = {0}; For[i = 1, i < n + 1, i++, AppendTo[xlist, Cos[i*(n - 1)/n*Pi]]; AppendTo[ylist, Sin[i*(n - 1)/n*Pi]]; points = Transpose[{xlist, ylist}]; AppendTo[plots, Graphics[Line[points], Axes -> True]] ]; Show[plots, PlotRange -> Full] ] I can't figure out how to make a function be called within a For Loop while also giving an output. The output works fine, just not in a For Loop. Any help is greatly appreciated.




Forloops never return anything. UseTableinstead:Table[ztar[i], {i, 1, 9, 2}]. See Alternatives to procedural loops and iterating over lists in Mathematica. $\endgroup$"Output"cell shows the value of an executed statement unless the value isNull. An"Input "cell may contain more than one statement and produce more than one"Output"cell.Printwrites a"Print"cell into the evaluation notebook,CellPrintcan write any type of cell into a notebook, etc. Personally, I avoidPrint[], esp. in loops, except for debugging (but still not in loops). Outside loops, it's mainly a style preference. If just learning Mma, style preferences should not be a priority, but avoiding an infinite loop ofPrint[]statements should be. $\endgroup$Showused to do what its name implies: show graphics. Now it is mainly used to combine multiple graphics. You can semi-emulate the old functionality withShow[plots, PlotRange -> Full, DisplayFunction -> Print]orDisplayFunction -> (CellPrint[ExpressionCell[#, "Output"]] &)$\endgroup$