# Pseudocode - repeat-until command

Hello how can I rewrite repeat until command so ''until'' in line 15 is closer to number 15 (not in the same column as line14)

\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{algorithm}
\clearpage
\begin{algorithm}
\caption{2-opt algoritmus}
\begin{algorithmic}[1]
\Repeat
\For{$i = 1$ do $n - 1$}
\For{$j = i + 1$ do $n$}
\If{$j < n$}
\If{$c(x_i, x_{i+1}) + c(x_j, x_{i+1}) < c(x_j, x_{i+1}) + c(x_j, x_{j+1})$}
\State Swap \textit{$x_i$} a \textit{$x_j$}
\EndIf
\Else
\If{$c(x_i, x_1) + c(x_n, x_{i+1}) < c(x_i, x_{i+1}) + c(x_n, x_1)$}
\State Swap \textit{$x_i$} a \textit{$x_n$}
\textbf{until}
\EndIf
\EndIf
\EndFor
\EndFor
\State
\textbf{Until}
\end{algorithmic}
\end{algorithm}
\end{document}

• The last \State should be removed and \textbf{Until} should be \Until{<some condition>}. As an aside, what's the purpose of \textit{$x_i$}? The \textit command does nothing at all. – egreg Apr 18 '19 at 22:11

The format for “repeat until” is

\Repeat
<body>
\Until{<condition>}


\documentclass{article}
\usepackage{amsmath}
\usepackage{algpseudocode}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}
\caption{2-opt algoritmus}
\begin{algorithmic}[1]
\Repeat
\For{$i = 1$ do $n - 1$}
\For{$j = i + 1$ do $n$}
\If{$j < n$}
\If{$c(x_i, x_{i+1}) + c(x_j, x_{i+1}) < c(x_j, x_{i+1}) + c(x_j, x_{j+1})$}
\State Swap $x_i$ a $x_j$
\EndIf
\Else
\If{$c(x_i, x_1) + c(x_n, x_{i+1}) < c(x_i, x_{i+1}) + c(x_n, x_1)$}
\State Swap $x_i$ a $x_n$
\EndIf
\EndIf
\EndFor
\EndFor
\Until{you're tired}
\end{algorithmic}
\end{algorithm}

\end{document}


Change “you're tired” with the proper condition.

• Thank you very mutch – Thomas Kyle Apr 19 '19 at 11:01