Did Petraeus do the right thing by resigning?

Citing an extramarital affair, CIA Director David Petraeus resigned his post. Today’s Question: Did CIA Director David Petraeus do the right thing when he resigned?