You do not need to know this within the loop of repetition to get this result, just remember that everything you run before the loop will always be before the first line, just as the one that runs after will be after the last line. So, you just need to do:
echo 'Antes da primeira linha';
while ($dados = mysqli_fetch_assoc($query)){
echo $dados['nome'];
}
echo 'Depois da última linha';
This maintains the legibility of the code and avoids having to evaluate two logical expressions at each loop. If you want to prevent messages from appearing when there are no records, just place that code snippet inside a if
with that condition.