How to? Logic in functions...

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
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
3,376
39
Albuquerque, NM
prospero.unm.edu
#2
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,203
11
Solon, OH, USA
#4
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
 
#5
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).