next up previous contents
Next: Calling a function Up: Lecture -1: A first Previous: Adding ``stop''   Contents

Adding a keyword

Again edit the hello_world.pro file so it contains
pro hello_world, number_questions,goodbye=goodbye
;+
;pro hello_world
;Procedure to print ``Hello world'' to screen then ask 'Anyone there?'
;number_questions  times. If goodbye set print 'Goodbye'
;
;Parameters:  number_questions - integer number of times to ask 'anyone there?'
;Keywords: goodbye, if this is set prints 'Goodbye' to screen
;John Marsham, (01/11/06)
;-

print,'Hello world' ;print the line ''Hello world'' to screen

for i=1,number_questions do begin
 print,'Anyone there?'
endfor

if keyword_set(goodbye) then print,'Goodbye'

stop; STOPS the program here

end

Type,

.compile hello_world
hello_world,3,goodbye=1
goodbye is a keyword of the procedure hello_world. Keywords are like optional parameters. Note the order doesn't matter since you set them with 'keywordname=something'. Note
.compile hello_world
hello_world,3,goodbye=2
Does the same thing, the goodbye keyword is still ``set''

.compile hello_world
hello_world,3,goodbye=0
Doesn't say goodbye. The goodbye keyword is not ``set''



lecjm 2008-11-06