Hi Arun92
If you have a ticket that must be punched to travel, it is mandatory to punch it. Such machine are available at every station: if there is a problem with one of them (defect, out of ink etc) please let the staff on board know as soon as you board the train.
If you have a day pass you can use it everywhere in Switzerland (within the borders) without punching it: it is valid one whole day, and the date is printed on the day pass already.
I wish you a nice day.
EleonoraS