From 58630bcb4334866b399da831c72e32c6674cd996 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Fri, 10 Jun 2011 16:28:14 +0530 Subject: ult: Add example for iterating over range of numbers. --- ult/handout.rst | 9 +++++++++ ult/ult.tex | 6 ++++++ 2 files changed, 15 insertions(+) (limited to 'ult') diff --git a/ult/handout.rst b/ult/handout.rst index b72dbdc..a1ea9fb 100644 --- a/ult/handout.rst +++ b/ult/handout.rst @@ -1910,6 +1910,15 @@ dummy or a loop variable. It can then be used to refer to the element of the list that is currently being dealt with. We could, obviously, use something as lame as ``i`` in place of ``animal``. +To generate a range of numbers and iterate over them, we do the following. + +:: + + for i in {5..10} + do + echo $i + done + Now, we use a ``for`` loop to list the files that we are interested in. :: diff --git a/ult/ult.tex b/ult/ult.tex index e1feb3d..613409f 100644 --- a/ult/ult.tex +++ b/ult/ult.tex @@ -1211,6 +1211,12 @@ \item Loop over the list; \texttt{animal} is a dummy variable \item Echo value of \texttt{animal} --- each name in list \end{itemize} + \begin{lstlisting} + for i in {10..20} + do + echo $i + done + \end{lstlisting} % $ \end{frame} \begin{frame}[fragile] -- cgit