EndLoop is the marker where the code block of the loop ends. The macro code between Loop and EndLoop has to be executed until the loop exits. ExitLoop breaks the loop immediately at this position and the macro continues with the command after EndLoop. So ExitLoop is just a JUMP to command after EndLoop.
It's also possible to run a loop without ExitLoop command if you need a defined number of loop execution. For example a simple loop macro to place the cursor at column 70 in the current line:
Key HOME
IfCoNumGt 1
Key HOME
EndIf
Loop
70
Key RIGHT ARROW
EndLoop
Your macro will also fail because you have nested loops - loop inside an existing loop. This is not possible in UE macro language.
IfNameIs "" means if the current file name is NULL which is true if no file is open or the current file is a new file which does not have a name until first save. So if you have only named files open, my macro exits after all files were modified and closed.
Well, this method will not work if you don't close a file if it does not contain the search term. You will produce an endless loop in this case because there will be always at least one file opened which has a name.
IfFound and IfNotFound can be used after a Find or Replace. It is possible to have other commands between Find/Replace and IfFound/IfNotFound although usually the condition commands are immediately after the Find/Replace command. The Replace command must be always immediately after the Find command. The IfFound/IfNotFound command must be below the Replace command and can be never between Find and Replace.
You can use ExitLoop as often as you want inside a loop.
ExitMacro at the end of the macro is useless because if there are no more macro commands the macro automatically ends. ExitMacro is only for exiting the macro execution anywhere inside the macro.
If you use IF conditions you have to write also the EndIf command for every IF condition or UE does not know which commands are for the current IF condition. An Example:
Code: Select all
IfSel
command 1
command 2
Else
Find "..."
IfFound
command 3
command 4
Else
Find "xxx"
IfNotFound
command 5
command 6
EndIf
EndIf
command 7
EndIf
In comparison to loops nesting of IF conditions is possible as you can see. Every command in this example can be also an ExitLoop command if this code block is inside a loop.
Note: Indenting the commands in the edit macro dialog is not possible. This example here is just for better understanding.
If you check the macro property
Continue if a Find with Replace not found my macro will also work for files which does not contain the search term. Those files are also saved and closed although nothing is changed by the macro because the string was not found.
If you must know which files do not contain the search string and you want those files open after the macro execution use following macro with macro property
Continue if a Find with Replace not found checked. It collects the file names with path of the files without the search string in user clipboard 9 and after first loop has finished and all open files are closed the macro runs a second loop to open the files without the search string. Make sure there is no space after first " at the 2 lines with only " before you copy the code into the edit macro dialog.
"
"
is the macro code to insert a line break to have later only one file name with path per line.
Here is the extended macro code which reopens the files which does not contain the search string. Make sure all files are saved before starting the macro or use SaveAll macro command before first loop because files without the search string are temporarily modified and so closed without saving (what you could also change) to not change the file time.
InsertMode
ColumnModeOff
HexOff
Clipboard 9
ClearClipboard
Loop
IfNameIs ""
ExitLoop
EndIf
Top
Find MatchCase MatchWord "TEST"
IfFound
"TERM1"
Find MatchCase MatchWord "TEST"
Replace "TERM2"
CloseFile Save
Else
Clipboard 8
CopyFilePath
Paste
"
"
Clipboard 9
SelectToTop
CutAppend
CloseFile NoSave
EndIf
EndLoop
NewFile
Clipboard 8
ClearClipboard
Clipboard 9
Paste
Top
Key END
Clipboard 9
IfColNum 1
CloseFile NoSave
ClearClipboard
Clipboard 0
ExitMacro
EndIf
Key HOME
Loop
StartSelect
Key END
Cut
EndSelect
Key DEL
Open "^c"
NextWindow
IfEof
ExitLoop
EndIf
EndLoop
CloseFile NoSave
ClearClipboard
Clipboard 0