Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!turnkey!orchard.la.locus.com!prodnet.la.locus.com!jfr From: jfr@locus.com (Jon Rosen) Newsgroups: comp.lang.pascal Subject: Re: User defined ordinal types Message-ID: <19956@oolong.la.locus.com> Date: 27 Nov 90 22:14:46 GMT References: <527@shum.UUCP> Organization: Locus Computing Corp, Los Angeles Lines: 41 In article <527@shum.UUCP> seran@vms.huji.ac.il writes: > > I am programming a pascal program using the vm compiler pascal. I am defining > a user defined type to be: > day_type= (sun,mon,tue,wed,thu,fri,sat); > I want to cycle through the days of the week but return to sun after sat. > I'd like to do this using a succ(day) which is in a loop counting the > days of the month. Also I would like to set the loop to start at Monday. > Is there any way of assigning the position to a user def. type? > And doing what I want to do? Thank you in advance, Eran... You are going to have to write your own function in Pascal that gets the next day for you... Function NextDay(ThisDay:day_type):day_type; Begin If ThisDay = Sat Then NextDay := Sun Else NextDay := Succ(ThisDay); End; This function will hide the details of cycling through the enumerated datatype. You can use this in an endless type of loop such as: CurrDay := Mon; While True Do Begin CurrDay := NextDay(CurrDay); End; Since the predefined identifier True is always true, the loop will continue endlessly cycling thru the days of the week. You will need some kind of a Break, Leave Exit or Goto to get out of the loop. I believe the VM Pascal compiler has a Leave statement. Good luck. Jon Rosen