How to? Logic in functions...

May 24, 2010
855
0
Northlake, Il
I found out in another thread that one could place logical statements (if, do while, etc.) into alias definitions, which I didn't know. I would assume, but possibly incorrectly, that one could not do that in function definitions except by executing a batch file via @ExecStr. Am I correct in that assumption?
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
I found out in another thread that one could place logical statements (if, do while, etc.) into alias definitions, which I didn't know. I would assume, but possibly incorrectly, that one could not do that in function definitions except by executing a batch file via @ExecStr. Am I correct in that assumption?

There is the @IF function. Be aware, though, that all of its arguments are evaluated -- regardless of whether the test condition is true or false.
 

samintz

Scott Mintz
May 20, 2008
1,555
26
Solon, OH, USA
Dan, here's an example of using @ExecStr with a DO loop.

Code:
function DoLogic=`%@execstr[SetLocal & Set C=0 & Do I=1 to %1 (Set C=%@inc[c]) & Echo C: %C I: %I & EndLocal]`
 
echo %@DoLogic[500]
C: 500 I: 501

-Scott
 
May 24, 2010
855
0
Northlake, Il
Scott, thank you for both giving me the answer and making me laugh. You effectively did a batch file, you just put it directly into the @ExecStr. Somehow it was in my mind that you could just execute external programs and batch files that way. And looking at the documentation (note Rex) there's not a clue that you can do that (although it certainly doesn't explicitly prohibit either).
 

Similar threads