!verbose 3 !macro If _a _o _b !insertmacro _PushLogic !define ${_Logic}EndIf _${__LINE__} ; Get a label for the (provisional) EndIf (it might turn out to be Else) !insertmacro _${_o} "${_a}" "${_b}" "" ${${_Logic}EndIf} !macroend !define If "!insertmacro If" !macro Else !ifndef _Logic | ${_Logic}EndIf !error "Cannot use Else without a preceding If" !endif !ifdef ${_Logic}Else !error "Cannot use Else after Else" !endif !define ${_Logic}Else ${${_Logic}EndIf} ; Save current Else label !undef ${_Logic}EndIf !define ${_Logic}EndIf _${__LINE__} ; Get a label for the (new) EndIf and go there Goto ${${_Logic}EndIf} ${${_Logic}Else}: ; Place the saved Else label !macroend !define Else "!insertmacro Else" !macro ElseIf _a _o _b !insertmacro Else ; Place in Else code as normal !undef ${_Logic}Else ; Forget the Else and perform the new If !insertmacro _${_o} "${_a}" "${_b}" "" ${${_Logic}EndIf} !macroend !define ElseIf "!insertmacro ElseIf" !macro EndIf !ifndef _Logic | ${_Logic}EndIf !error "Cannot use EndIf without a preceding If" !endif ${${_Logic}EndIf}: ; Place the EndIf !undef ${_Logic}EndIf !ifdef ${_Logic}Else !undef ${_Logic}Else ; Clear the Else flag !endif !insertmacro _PopLogic !macroend !define EndIf "!insertmacro EndIf" !macro While _a _o _b !insertmacro _PushLogic !define ${_Logic}While _${__LINE__} ; Get a label for the start of the loop !define ${_Logic}EndWhile _${__LINE__} ; Get a label for the end of the loop ${${_Logic}While}: ; Insert the loop condition !insertmacro _${_o} "${_a}" "${_b}" "" ${${_Logic}EndWhile} !macroend !define While "!insertmacro While" !macro EndWhile !ifndef _Logic | ${_Logic}While !error "Cannot use EndWhile without a preceding While" !endif Goto ${${_Logic}While} ; Loop back to the While condition ${${_Logic}EndWhile}: ; Place the EndWhile !undef ${_Logic}While !undef ${_Logic}EndWhile !insertmacro _PopLogic !macroend !define EndWhile "!insertmacro EndWhile" !macro Do !insertmacro _PushLogic !define ${_Logic}Do _${__LINE__} ; Get a label for the start of the loop ${${_Logic}Do}: !macroend !define Do "!insertmacro Do" !macro EndDo _a _o _b !ifndef _Logic | ${_Logic}Do !error "Cannot use EndDo without a preceding Do" !endif !insertmacro _${_o} "${_a}" "${_b}" ${${_Logic}Do} "" !undef ${_Logic}Do !insertmacro _PopLogic !macroend !define EndDo "!insertmacro EndDo" !macro _PushLogic !ifdef _Logic ; If we already have a statement !define _CurLogic ${_Logic} !undef _Logic !define _Logic _${__LINE__} !define ${_Logic}Prev ${_CurLogic} ; Save the current logic !undef _CurLogic !else !define _Logic _${__LINE__} ; Initialise for first statement !endif !macroend !macro _PopLogic !ifdef ${_Logic}Prev ; If a previous statment was active then restore it !define _CurLogic ${_Logic} !undef _Logic !define _Logic ${${_CurLogic}Prev} !undef ${_CurLogic}Prev !undef _CurLogic !else !undef _Logic !endif !macroend ; String tests !macro _== _a _b _t _f StrCmp "${_a}" "${_b}" "${_t}" "${_f}" !macroend !macro _!= _a _b _t _f !insertmacro _== "${_a}" "${_b}" "${_f}" "${_t}" !macroend ; Integer tests !macro _= _a _b _t _f IntCmp "${_a}" "${_b}" "${_t}" "${_f}" "${_f}" !macroend !macro _<> _a _b _t _f !insertmacro _= "${_a}" "${_b}" "${_f}" "${_t}" !macroend !macro _< _a _b _t _f IntCmp "${_a}" "${_b}" "${_f}" "${_t}" "${_f}" !macroend !macro _>= _a _b _t _f !insertmacro _< "${_a}" "${_b}" "${_f}" "${_t}" !macroend !macro _> _a _b _t _f IntCmp "${_a}" "${_b}" "${_f}" "${_f}" "${_t}" !macroend !macro _<= _a _b _t _f !insertmacro _> "${_a}" "${_b}" "${_f}" "${_t}" !macroend !verbose 4 Name "If Macros Test" OutFile If.exe Section ${If} 1 = 01 MessageBox MB_OK "1 = 1" ${EndIf} ${If} -01 <> -1 MessageBox MB_OK "-1 <> -1" ${EndIf} ${If} $TEMP == "c:\windows\temp" MessageBox MB_OK "$$TEMP is c:\windows\temp" ${Else} MessageBox MB_OK "$$TEMP is not c:\windows\temp" ${EndIf} ${If} $PROGRAMFILES != "c:\program files" MessageBox MB_OK "$$PROGRAMFILES is not c:\program files" ${Else} MessageBox MB_OK "$$PROGRAMFILES is c:\program files" ${EndIf} ${If} -1 = 0 MessageBox MB_OK "-1 = 0" ${ElseIf} -1 < 0 MessageBox MB_OK "-1 < 0" ${Else} MessageBox MB_OK "-1 > 0" ${EndIf} ${If} 2 >= 1 MessageBox MB_OK "2 is not less than 1" ${If} 2 = 1 MessageBox MB_OK "but 2 is equal to 1" ${Else} MessageBox MB_OK "2 is not equal to 1 either" ${EndIf} MessageBox MB_OK "End of the correct nested test" ${Else} MessageBox MB_OK "2 is less than 1" ${If} 2 = 1 MessageBox MB_OK "and 2 is equal to 1 too" ${Else} MessageBox MB_OK "but 2 is not equal to 1" ${EndIf} MessageBox MB_OK "End of the incorrect nested test" ${EndIf} StrCpy $1 0 ${While} $1 < 10 ${If} $1 = 9 MessageBox MB_OK "Last set..." ${EndIf} StrCpy $2 $1 ${Do} MessageBox MB_OK "$$1 is $1, $$2 is $2" ${If} $1 = 9 ${If} $2 = 0 MessageBox MB_OK "That was the last one" ${EndIf} ${EndIf} IntOp $2 $2 - 1 ${EndDo} $2 >= 0 IntOp $1 $1 + 1 ${EndWhile} SectionEnd