# How to put texts on a newline in an algorithm (in a nested for-loop)?

I am making an algorithm with a nested for loop, and there are multiple in the loop. They are presented on the same line, but I want them to start on a newline. Any ideas how I can do this?

This is my code:

\begin{algorithm}
\begin{algorithmic}[1]
\State {Input $\pi$, the random policy}
\State {Initialize V(s)=0 for all s $\in$ S}
\State {Repeat}
\State {$\Delta$ \gets 0}

\For{for each s $\in$ S }:
\For{for each direction $\in$ directions }:
\For{for slide in slides}:
\State{v \gets V(s)}
\State{V(s) \gets \sum_{a} $\pi${(s,a)}\sum_{s'}P_{ss'}^{a}[R_{ss'}^{a}+\gamma V(s')]}
\State{$\Delta$ \gets max($\Delta$,\mid v-V(s)\mid)}
\State{Until $\Delta$ < $\Theta$ ($\Theta$ = 0,01}
\State{Output V \approx V^{$\pi$}}
\EndProcedure
\end{algorithmic}
\caption{Policy evaluation}
\end{algorithm}

• Welcome to TeX SX! What exactly should be on a separate line? Apr 28, 2019 at 20:33

Well, because you gave us no complete compilable TeX code (MWE) I have to guess. Based on your given code snippet I used packages algorithm and algpseudocode and added the missing \EndFor commands. And I corrected, added or moved some $ in your code ... Please see the following MWE \documentclass{article} \usepackage{algorithm}% <=========================== \State \usepackage{algpseudocode} \begin{document} \begin{algorithm} \begin{algorithmic}[1] \Procedure{test}{Output} % <============================================ \State {Input$\pi$, the random policy} \State {Initialize V(s)=0 for all s$\in$S} \State {Repeat} \State {$\Delta \gets 0$} \For{for each s$\in$S} \For{for each direction$\in$directions} \For{for slide in slides} \State{v$\gets$V(s)} \State{$V(s) \gets \sum_{a} \pi{(s,a)}\sum_{s'}P_{ss'}^{a}[R_{ss'}^{a}+\gamma V(s')]$} \State{$\Delta \gets max(\Delta,\mid v-V(s)\mid)$} \State{Until$\Delta$<$\Theta$($\Theta$= 0,01} \State{Output$V \approx V^{\pi}\$}
\EndFor% <==========================================================
\EndFor% <============================================================
\EndFor% <==============================================================
\EndProcedure
\end{algorithmic}
\caption{Policy evaluation}
\end{algorithm}

\end{document}


and its result: