I am sure that I overlooked something very obvious. Still, why does the example in this nice answer work, but if I remove the loop, I get an error about a grouping mismatch?
Consider the following minimal non-working example:
\documentclass{article}
\begin{filecontents}{\jobname.bib}
@article{testref,
author = {Miller, Alice and Highlight, Shine and Smith, Bob},
title = {The title},
journal = {The journal},
pages = {65--78},
year = 2014}
\end{filecontents}
\usepackage{xpatch}
\usepackage[normalem]{ulem}
\usepackage[backend=biber,bibencoding=utf8,style=numeric-comp,maxbibnames=99]{biblatex}
\addbibresource{\jobname.bib}
\newbox\savenamebox
% does not work
\newbibmacro*{name:bbold}[2]{%
\iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}%
{\bfseries\setbox\savenamebox\hbox\bgroup\listbreak}{}%
}
\newbibmacro*{name:ebold}[2]{%
\iffieldequalstr{hash}{01b588ba4e4ad753feae6c81709fc04b}%
{\egroup\uline{\usebox\savenamebox}\listbreak}{}%
}
% ===
\xpatchbibmacro{name:given-family}{\usebibmacro{name:delim}{#2#3#1}}{\usebibmacro{name:delim}{#2#3#1}\begingroup\usebibmacro{name:bbold}{#1}{#2}}{}{}
\xapptobibmacro{name:given-family}{\usebibmacro{name:ebold}{#1}{#2}\endgroup}{}{}
\begin{document}
\nocite{*}
\printbibliography
\end{document}
The original code has instead
\newbibmacro*{name:bbold}[2]{%
\def\do##1{\iffieldequalstr{hash}{##1}{\bfseries\setbox\savenamebox\hbox\bgroup\listbreak}{}}%
\dolistloop{\boldnames}%
}
\newbibmacro*{name:ebold}[2]{%
\def\do##1{\iffieldequalstr{hash}{##1}{\egroup\uline{\usebox\savenamebox}\listbreak}{}}%
\dolistloop{\boldnames}%
}
\newcommand*{\boldnames}{}
\forcsvlist{\listadd\boldnames}{
{4fcd4bca11ef811f3aef17c792b6ef3e},
{01b588ba4e4ad753feae6c81709fc04b}}
This works well. But why is this? Does the loop somehow delay expansion so that the grouping mismatch is irrelevant? How could I get a working example without a loop?

\listbreakleft-overs from the original code. Try without them. – user691586 Apr 13 '23 at 07:05\listbreakis actually needed to go through the list generated by\forcsvlist, right? Then it makes a lot of sense that this macro should not be part of the macros without the loop! Thank you! – Jasper Habicht Apr 13 '23 at 08:56latexdef -p etoolbox listbreakreturns\listbreak:\long macro:#1&->so it looks like a clean-up thing, I did not check the catcode of the&though. I guess it does what its name indicates, breaking out of a loop and for whatever reason that was needed in the original code you started with. – user691586 Apr 13 '23 at 09:48