\documentclass{article}

\begin{document}

\newenvironment{env1}{}{}
\newenvironment{env2}{}{}
\newenvironment{env3}{}{}
\newenvironment{env4}{}{}

% environments on separate lines
\begin{env1}
\begin{env2}
\end{env2}
\end{env1}

% environments on shared lines
\begin{env1}\begin{env2}
\end{env2}\end{env1}

% environments on shared lines with spaces
\begin{env1} \begin{env2}
\end{env2} \end{env1}

% environments all on same line
\begin{env1}\begin{env2}\end{env2}\end{env1} % with a comment \begin{env1}

% environments with extra brackets
\begin{env1}(a)(b \begin{env2}[c{d}e] \end{env2}[f]g)\end{env1}

% environments and a long line
\begin{env1}\begin{env2}\begin{env3}\begin{env4}\end{env4}\end{env3}\end{env2}\end{env1}

\end{document}
