The following macro illustrates how to use DIESEL to perfrom a loop operation. This macro calculates the factorial of a given number by iterating a required number of times. You can use the same logic to create various loop structures as per your requirement.

*^C^C$M=$(if,$(<=,$(getvar,USERI2),$(getvar,USERI1)),setvar;USERI3;$M=$(if,$(=,$(getvar,USERI2),1),1,$(*,$(getvar,USERI2),$(getvar,USERI3)));setvar;USERI2;$(+,$(getvar,USERI2),1),_modemacro;"The factorial of "$(getvar,USERI1)" is "$(getvar,USERI3);^C)

Before using the above macro, you need to run a simple macro to set up the user variables and the status bar. You need to supply the required number at the USERI1 prompt.

^C^C_modemacro;.;setvar;useri1;\;setvar;useri2;1;setvar;useri3;0;

Isn't it quite simple to do an iteration using DIESEL? Basically a loop macro has the following componetns.

- *^C^C in the beginning to have continuous operations
- A conditional statement using a counter variable to continuously check against the loop upper limit.
- If the condition is not met, do the required operations and continue.
- If the condition is met, then terminate the macro using ^C at the end.

## 1 comment:

Dear Haris

My name is Idrees I am working in Abu dhabi as electical Design and draftsman

Could u contact to me this email ID

idreestirur@gmail.com

Post a Comment