while

With much reading and practice I have become a bit familiar with writing autolisp routines. Things I couln't do a year ago are now becoming quite
simple. One thing, however I'm having trouble with is using "while" for loops. Can anyone explain the "while" function and how it works, maybe with a couple of examples. I'm especially baffled by how it is used to read down a data list, looking for info. Any help would be appreciated.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
(while (some condition exists) (do this) (and do this) (and this...) );; end while
"Some condition" can be T or nil, an equality, or whatever. For example:
(setq counter 10) (while (> counter 0) (princ (strcat "\n" (atoi counter))) (setq counter (1- counter)) );; while (princ)
As for your "data list" if it's in the form of a LISP list, you can use the counter variable to get the "nth" element of the list, as in (setq dat (nth datalist counter)) and so on.
If you're reading data from a file, all you have to do is to verify that there's another element available:
(while (setq dat (read-line infile)) (do things) (do more stuff) )
(read-line ...) returns nil after it passes the last element of the file, exiting the loop. ___

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Thanks Paul. That was very simple yet concise. It will help a great deal. Thanks again.

looking
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.