Re: Two possible bugs in docs!
- Posted by "Graeme." <hmi at POWERUP.COM.AU> Jun 20, 1998
- 724 views
At 08:54 AM 6/19/98 -0400, Alan wrote something. Despite the smoewhat off-topic heading for this message, I believe you are looking for clarification on 1) for loops and 2) using variable types as functions. 1) For loops >include file.e > >integer fn >fn = open("mydata", "r") --<opens file > >-- read and display first line of file 3 times: > >for i = 1 to 3 do --<declares i = 1 > puts(1, gets(fn)) --<gets and displays a line > if seek(fn, 0) then --<rewinds to offset 0 > puts(1, "rewind failed!\n") > end if >end for --<i=i+1 do it again until i=3 The variable i is declared when the for loop is declared and exists only inside the loop. This loop executes 3 times, so the code inside it is repeated 3 times. Try this: for number=0 to 9 do puts(1,"\nnumber :") print(1,number) end for 2) Using Types as Functions A type such as atom and integer or a user defined type can be called like a normal function to check a value against the defined limits of the type. > line = gets(0) > if atom(line) then > puts(SCREEN, "end of file\n") > end if the second line here means: If the variable "line" is an atom then... The gets() function will return a sequence unless it reaches the end of file, when it will return -1 (an atom), So if variable "line" is an atom and not a sequence then the end of the file has been reached. Graeme. ----------------------------------------------------