(1)Whenever any person is convicted of an offence punishable under Section 34 or Section 36; and the Magistrate convicting him is of opinion that it is necessary to require such person to execute a bond to abstain from the commission of offences punishable under those section; the Magistrate may, at the time of passing sentence on such person, order him to execute a bond for a sum proportionate to his means, with or without sureties, to abstain from the commission of such offences during such period, not exceeding three years, as he may direct.