Rooting an S4. (Just a quick question)

Does it need to be unlocked to be rooted or I can root it even if locked to a carrier?