Life is traditionally divided into four stages, and the first is brahmacharya, the student's life of discipline and study
Hindu law codified continence not as an occasional discipline but as a mandatory life stage that every student was expected to pass through before marriage was even permitted.
The Manusmriti, a Sanskrit legal and ethical text compiled over centuries, lays out the ashrama system in its second chapter: four sequential stages of life — brahmacharya (student), grihastha (householder), vanaprastha (forest-dweller), and sannyasa (renunciant). Brahmacharya comes first by design, not incidentally: the text treats celibate discipline as formation that must precede family life, not an alternative to it. A young man in this stage lived with a guru, studied the Vedas, and was expected to remain sexually continent for the duration of his studentship, which could last many years. The ordering matters theologically — Manu's system assumes a person cannot responsibly enter household life, with its obligations and desires, without first mastering restraint as a discipline in its own right.
The Manusmriti's final compilation is generally dated between the 2nd century BCE and 2nd century CE, though it draws on much older oral legal tradition.
Manusmriti