Consider the code
\documentclass{article}
\usepackage{listings}
\usepackage{cleveref}
\crefname{lstnumber}{line}{lines}
\Crefname{lstnumber}{Line}{Lines}
\begin{document}
\begin{lstlisting}[escapechar=@,numbers=left]
{A}@\label{lineref1}@
x:=1@\label{lineref2}@
{B}@\label{lineref3}@
y:=2@\label{lineref4}@
{C}@\label{lineref5}@
\end{lstlisting}
See the Hoare-triples at \namecrefs{lineref1} \ref{lineref1}--\ref{lineref3}, \ref{lineref3}--\ref{lineref5}.
%\labelcrefrange{lineref1}{lineref3}, \labelcrefrange{lineref3}{lineref5}
\end{document}
With the (non-existing) \labelcrefrange, the input could have been a little bit more abstract: one would have to provide the format for the ranges only once per document (as opposed to spelling out the double hyphen without surrounding spaces on each use). Does such a command exist in cleveref (or some other standard packages)?


\crefrange? To get the dash you'll also need to add\newcommand{\crefrangeconjunction}{--}to your preamble. See this answer. – Circumscribe Sep 29 '18 at 22:49