# What are the restrictions on preparing spells following a long rest? [duplicate]

For spell casting classes like clerics, druids and wizards they can change their prepared spells following a long rest. Does this have to be immediately following a long rest with nothing in between or could a character cast some spells first?

For example, a wizard might cast mage armor on themselves following a long rest, but then prepare a new set of spells not including mage armor.

Also, are you restricted to preparing new spells only once per long rest? Or could a spell caster prepare spells, cast one or more of then, then prepare a new spell list?