

% add the PATH to retrieve cls and sty beamer styles files
\makeatletter
\providecommand*{\input@path}{}
\edef\input@path{{../../support/beamer/}\input@path}% prepend
\makeatother

% \documentclass{pharoslides}
% \documentclass[aspectratio=169]{pharoslides} % format 16/9
\documentclass[withvideo]{pharoslides} % format 16/9 + incrustation video

\graphicspath{{./figures/}{../}{../../support/beamer/imgs/}}

%Information to be included in the title page:
\title{Loops}
\subtitle{}
\author{Damien Cassou, Stéphane Ducasse and Luc Fabresse}
\institute{http://stephane.ducasse.free.fr}
\date{}
\slidesid{W2S07}

\begin{document}

\frame[plain]{\titlepage}



\begin{frame}[fragile]

\frametitle{Loops}

\begin{itemize}
\item Loops are expressed as messages
\item Many different ones
\begin{itemize}
\item Plain loops
\item Conditional loops
\end{itemize}

\item Messages sent to numbers, collections or blocks
\item Iterators
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: timesRepeat:}

To repeat a given number of times an action

\begin{listing}{}
	4 timesRepeat: [ self doSomething ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: to:do:}

\begin{listing}{}
1 to: 100 do:
    [ :i | ... i ... ]
\end{listing}

\code{to:do:} is a method defined on \code{Number}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: to:do:}

The block is executed with the temporary \code{i} taking values from 1 to 100
 

\begin{listing}{}
1 to: 100 do:
    [ :i | Transcript show: i ; space ]
\end{listing}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/1to100.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: to:by:do:}

\begin{listing}{}
    0 to: 100 by: 3 do: [ :i | ... i ... ]
\end{listing}

\code{to:by:do:} is also a method defined on \code{Number}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: to:by:do:}

The block is executed with i taking values from 1 to 100 by step of 3

\begin{listing}{}
1 to: 100 by: 3 do:
    [ :i | Transcript show: i ; space ]
\end{listing}


\begin{center}
\includegraphics[width=1.0\textwidth]{figures/1to100by3.png}\end{center}

\end{frame}



\begin{frame}[fragile]

\frametitle{Basic Iterators Overview}

\begin{itemize}
\item \code{do:} (iterate)
\item \code{collect:} (iterate and collect results)
\item \code{select:} (select matching elements)
\item \code{reject:} (reject matching elements)
\item \code{detect:} (get first element matching)
\item \code{detect:ifNone:} (get first element matching or a default value)
\item \code{includes:} (test inclusion)
\item and a lot more...
\end{itemize}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: do:}

\begin{listing}{}
    aCol do: [ :each | ... ]
\end{listing}

The block is executed with \code{each} taking as value all the elements of \code{aCol}
\end{frame}



\begin{frame}[fragile]

\frametitle{Example: The iterator do:}

\begin{listing}{}
#(15 10 19 68) do:  
      [:i | Transcript show: i ; cr ]
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: whileTrue:}

\begin{listing}{}
    [ ... ] whileTrue: [ ... ]
\end{listing}

Executes the argument, \code{aBlock}, as long as the value of the receiver is true 

\begin{listing}{}
Color >> atLeastAsLuminentAs: aFloat 
  | revisedColor |
  revisedColor := self.
  [ revisedColor luminance < aFloat ] 
     whileTrue: [ revisedColor := revisedColor slightlyLighter ].
  ^ revisedColor
\end{listing}
\end{frame}



\begin{frame}[fragile]

\frametitle{Loops: whileTrue}

Executes the receiver, as long as its value is true

\begin{listing}{}
    [ ... ] whileTrue
\end{listing}

Equivalent with \code{whileFalse} and \code{whileFalse:}
\end{frame}



\begin{frame}[fragile]

\frametitle{Summary}

\begin{itemize}
\item Loops are expressed as messages
\item Many different ones
\begin{itemize}
\item Plain loops
\item Conditional loops
\end{itemize}

\item Messages sent to numbers, collections or blocks
\item Iterators
\end{itemize}
\end{frame}




% \setlength{\textwidth}{\originaltextwidth}
\setbeamertemplate{background canvas}{\insertBorderForHandout}

\begin{frame}[plain]

\begin{minipage}{\originaltextwidth}
\centering
\large


\vspace{2em}

A course by

\vspace{1em}

\hspace{-20px}\includegraphics[height=32px]{inriaLogo}\hspace{3em}\raisebox{7px}{and}\hspace{3em}\raisebox{-6px}{\includegraphics[height=30px]{logoutop}}

\vspace{2em}

in collaboration with

\vspace{1em}

\includegraphics[height=40px]{unisciellogo}\hskip 1.5em%
\raisebox{5px}{\includegraphics[height=30px]{unitlogo}}\hskip 2em%
\raisebox{8px}{\includegraphics[height=24px]{univLilleLogo}}\hskip 2em%
\raisebox{3px}{\includegraphics[height=29px]{logo-IMT}}\hskip 2em%
\raisebox{1px}{\includegraphics[height=32px]{minesDouaiLogo}}

\vspace{2.5em}

\includegraphics[width=50px]{by-nc-nd} \tiny \hskip 0.5em \raisebox{5px}{Inria 2016}

\medskip

\tiny
Except where otherwise noted, this work is licensed under CC BY-NC-ND 3.0 France

\url{https://creativecommons.org/licenses/by-nc-nd/3.0/fr/} 

\end{minipage}
\end{frame}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
