[Newbies] Re: if absent put nil (Riaan)

Zulq Alam me at zulq.net
Wed Aug 6 12:53:25 UTC 2008


I would probably do as Klaus suggests but you could also use a cascade 
and then #ifEmpty:. For example:

self workSession attendees
   do: [:each | html text: each person displayString]
     separatedBy: [html text: '; '] ;
   ifEmpty: [html text: 'NO ATTENDEES']	

Note the cascade ";" at the end of the third line. This sends 
#do:seperatedBy: and then sends #ifEmpty: to the collection returned by 
#attendees. Of course, #ifEmpty: and #do:separatedBy: will only do 
something if the collection is either empty or not.

Regards,
Zulq.

Riaan van Aarde (SpeCon Eng.) wrote:
> I have the following code
> 
> renderAttendeesOn: html
> 	self workSession attendees do: [:each | html text: each person
> displayString] 
> 			separatedBy: [html text:'; '.]
> 
> if there is no attendees for my worksession, it needs to display : NO
> ABSENTEES.
> 
> Please assist.
> 



More information about the Beginners mailing list