I defined a new float environment for examples
\usepackage{float
\newfloat{example}{htp}{example}
\floatname{example}{Example}
that I the use throughout the document
\begin{example}
...
\caption{yet another example}
\end{example}
with automatic numbering and a table of examples
\listof{example}{List of Examples}
Now I have some long examples that I wish not to put in a float but give as subsections:
\subsection*{A long example}
...
How can I make this subsection to get included in the numbering of examples (with title "Example X: A long example") and appear in the list of examples?
P.S.: Claudio Fiandrino has provided a boilerplate which I adopted for my document the following way (looks like the solution depends on you document style, I use scrbook):
\newcommand{\subsectionexample}[1]{
\stepcounter{example}
\subsection*{Example \theexample: #1}
\addcontentsline{example}{example}{\protect\numberline{\theexample}#1}
}
\subsectionexample{A long example}
....

