How can I do this while loop in 1 line

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

How can I do this while loop in 1 line

15 Feb 2018, 16:27

Hi,

Seems like a simple question but I wasn't able to come with the right syntax.

I would like something like
while the regexmatch is not null and <= LengthLim, store it in TempFoundDelimPos and do ...

Code: Select all

while (TempFoundDelimPos:=regexmatch(TextToWrapNew,P_RegexDelim,,CurrPos)<=LengthLim) {
			...
			}
Instead of writing

Code: Select all

while (regexmatch(TextToWrapNew,P_RegexDelim,,CurrPos) and regexmatch(TextToWrapNew,P_RegexDelim,,CurrPos)<=LengthLim) {
			TempFoundDelimPos:=regexmatch(TextToWrapNew,P_RegexDelim,,CurrPos)
			...
			}
Which is long, redundant and performs 3 same regexmatch

Thanks ! ;)
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: How can I do this while loop in 1 line

15 Feb 2018, 16:48

I do this set up

Code: Select all

pos:=1
while (pos<=LengthLim) && (pos>0) ; it returns 0 when not found, not sure if you could use ErrorLevel here
{
pos:=regexmatch(haystack,needle)
do stuff
}
This does assume that you will find a result each time. You could work around that with this logic actually:

Code: Select all

pos:=regexmatch(haystack,needle)
while (pos<=LengthLim) && (pos>0)
{
do stuff
pos:=regexmatch(haystack,needle)
}
This way, the while loop is only ever entered if pos returned a good result for you. Once it's in the while loop, the last thing it does is updates pos, which will make the while expression evaluate to see if it should repeat itself or move beyond the loop.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: How can I do this while loop in 1 line

15 Feb 2018, 19:14

Right, seems simple that way :)
I thought I was missing the syntax to set it up directly but I guess that means it is not so easy.
Anyway, the trick seems fine, many thanks !
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], inseption86, jaka1, metallizer, Rohwedder and 318 guests