Exploration of jet substructure using iterative declustering in pp and Pb–Pb collisions at LHC energies