Y
Y
Yan2020-08-09 14:26:48
cmd/bat
Yan, 2020-08-09 14:26:48

How to merge functions correctly in cmd GTR LSS?

THE CODE
set cntStart=1
set cntEnd=200
set number=
set addZero=2
setlocal enabledelayedexpansion
for /l %%i in (%cntStart%,1,=%cntEnd%) do (
  if %%i LSS 10 (
    if %addZero% EQU 1 (
      set number=0%%i
    ) else if %addZero% EQU 2 (
      set number=00%%i
    ) else (
      set number=%%i
    )
  ) else if (%%i GTR 10 & %%i LSS 100 (
    if %addZero% EQU 1 (
      set number=%%i
    ) else if %addZero% EQU 2 (
      set number=0%%i
    ) else (
      set number=%%i
    )

  ) else (
    set number=%%i
  )


This line is of interest
) else if (%%i GTR 10 & %%i LSS 100 (
Condition if the variable is greater than 10 and less than 100 then further down the list
Now the command does not run at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan, 2020-08-09
@Slayer_nn

Nest IFs
IF CONDITION 1 (
IF CONDITION2 COMMAND A
)

else if %%i LSS 100 (
   	if %%i GEQ 10 (
      if %addZero% EQU 1 (
        set number=%%i
      ) else if %addZero% EQU 2 (
        set number=0%%i
      ) else (
        set number=%%i
      )
    )
  )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question