How to create a triangle of dots in TikZ using the foreach command?
I need this.

How to create a triangle of dots in TikZ using the foreach command?
I need this.

The simplest solution that respects the question of the OP (a triangle of dots with Tikz) seems to be :
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \y in {0,...,4}
\foreach \x in {-\y,...,\y}
\fill [blue] (\x,-\y) circle [radius=0.2];
\end{tikzpicture}
\end{document}
You can use the option [evaluate = <variable> as <macro> using <expression>] to calculate a new value based on a counter, which can then be used in an inner counter:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach [evaluate = \y as \n using \y*2-1] \y in {1,...,5} {
\foreach \x in {1,...,\n} {
\fill [blue] (\x-\n/2,-\y) circle [radius=3pt];
}
}
\end{tikzpicture}
\end{document}

User defined constants:
\FPset{H}{5}% Height

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\usepackage[nomessages]{fp}
% user defined constants
\FPset{H}{5}% Height
% internal used constants
\FPeval{Size}{H-1}
\begin{document}
\begin{pspicture}(-\Size,-\Size)(\Size,0)
\multido{\iY=0+1}{\H}{%
\FPeval{N}{round(2*\iY{}+1:0)}%
\multirput(-\iY,-\iY)(1,0){\N}{\pscircle*[linecolor=blue](0,0){5pt}}}
\end{pspicture}
\end{document}
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add,tikz}
\usepackage[nomessages]{fp}
% user defined constants
\FPset{H}{5}% Height
% internal used constants
\FPeval{Size}{H-1}
\begin{document}
\begin{pspicture}(-\Size,-\Size)(\Size,0)
\foreach \y in {0,...,\H}
\foreach \x in {-\y,...,\y}
{\pscircle*[linecolor=blue](\x,-\y){5pt}}
\end{pspicture}
\end{document}
User defined data:
\FPset{N}{6}

\documentclass[border=-0.5cm,pstricks]{standalone}%a negative length is set to border to trim the unwanted white spaces!
\usepackage{pstricks-add,fp}
% user defined data
\FPset{N}{6}
% internal used data
\FPeval{H}{round(N-1:0)}
\FPeval{W}{round(2*H+1:0)}
\pstVerb{/Left {\N\space 0.25 2 sqrt mul \H\space add neg} def}
\begin{document}
\begin{pspicture}(-\N,-\N)(\N,1)
\psclip{\pspolygon[linestyle=none](0,0.5)(!Left)(!Left 2 1 roll neg exch)}
\multirput(0,0)(0,-1){\N}{\multirput(-\H,0)(1,0){\W}{\pscircle*(0,0){5pt}}}
\endpsclip
\end{pspicture}
\end{document}
Jake's answer is very neat, and I was happy to learn about evaluate, but you do not need it. The following does the trick using more elementary code:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \y in {0,...,4} {%
\foreach \x in {0,...,\y} {%
\fill [blue] (\x,-\y) circle [radius=3pt];
\fill [blue] (-\x,-\y) circle [radius=3pt];
}
}
\end{tikzpicture}
\end{document}
\fill ... line, which could become a bit annoying if you want to change the colour, shape or radius of the points. 2) The dots in the middle column are drawn twice, which can lead to undesirable results if you use transparency.
– Jake
Jul 26 '11 at 23:31