fun with enumeration
Posted: Mon Aug 04, 2008 8:28 pm
there are for basic enumeration or looping functions in Transcendence but there is only one needed and that is loop.
(loop conditional function)
A loop works like this.
First you check the conditional if false go to the code after the loop.
If true run the function.
Go to the conditional.
Now that we know how the loop works then lets make the other kind of loop.
(enum mylist variable function)
Not too hard just have a extra variable. index
(enumwhile list condition variable function)
Nearly the same as enum but has an extra condition.
(for variable startNumber endNumber function)
For is simpler than the others.
And for a bonus while not in transcendence many have a do while. Basically think of a loop that has the conditional at the bottom instead of the top.
Any questions or comments?
(loop conditional function)
A loop works like this.
First you check the conditional if false go to the code after the loop.
If true run the function.
Go to the conditional.
Now that we know how the loop works then lets make the other kind of loop.
(enum mylist variable function)
Not too hard just have a extra variable. index
Code: Select all
(setq index 0)
(setq listSize (count myList))
(loop (ls index listSize)
(setq variable (item myList index))
;put the function here
(setq index (add index 1))
)
Nearly the same as enum but has an extra condition.
Code: Select all
(setq index 0)
(setq listSize (count myList))
(loop (and (ls index listSize) condition)
(setq variable (item myList index))
;put the function here
(setq index (add index 1))
)
For is simpler than the others.
Code: Select all
(setq index startIndex)
(loop (leq index endIndex)
(setq variable index)
;put the function here
(setq index (add index 1))
)
Code: Select all
(setq runOnce True)
(loop (or runOnce conditional)
;put the function here
(setq runOnce nil)
)