seran@VMS.HUJI.AC.IL (ERAN MEGIDO) (11/27/90)
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... Please send the answer, if possible, to SERAN@HUJIVMS.bitnet or seran@vms.huji,ac,il on internet. bitnet is preffered.
jfr@locus.com (Jon Rosen) (11/28/90)
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 <loop body> 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