# In PStricks, what is the difference between \psforeach and \multido in the following?

My code:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb,newcent}
\usepackage{pstricks}
\usepackage{multido}
\usepackage{auto-pst-pdf}
\begin{document}

\begin{pspicture}(-.5,-1.5)(6.5,1.5)
\psforeach{\m}{.5,1.5,2.5,3.5,4.5,5.5}{\psline(0,\m)(\m,0)}
\end{pspicture}

\begin{pspicture}(-.5,-1.5)(6.5,1.5)
\multido{\n=0.5+1}{6}{\psline(0,\n)(\n,0)}
\end{pspicture}
\end{document}


The result compiling:

Question:

These commands are equivalent !?. Why are there differences?

for equidistant values it makes no difference. But \multido cannot work with something like 1, 1, 2, 3, 5, 8, ... and, of course, \multido uses some predefined macros:

\i   for integers
\n   for natural numbers
\r   for real


In your example it should be

\multido{\r=0.5+1}{6}{\psline[linecolor=red](0,\r)(\r,0)}

• In above question, \multido{\n=0.5+1}{6}, it has also equidistant values. So, can you explain more clearly? – Trong Vuong Dec 8 '18 at 10:55
• see edited answer – user2478 Dec 8 '18 at 11:05
• for multido everything is declared in the documentation. For psforeach you can use any macro you like and which is not already defined. – user2478 Dec 8 '18 at 11:27
• please answer the above question! – Trong Vuong Dec 8 '18 at 11:29
• @chishimotoji you can use for example \multido{\ri=0.5+1}{6}{\psline(0,\ri)(\ri,0)} or \multido{\ra=0.5+1}{6}{\psline(0,\ra)(\ra,0)} – user139826 Dec 8 '18 at 12:09