[solved] if A or B
Posted: 01 Oct 2007 01:01
is there any way of getting an if A or B (do something) construct?
Code: Select all
set "true="
if "%~1"=="a" set "true=Y"
if "%~1"=="b" set "true=Y"
if "%~1"=="c" set "true=Y"
if defined true (echo.At least one condition was TRUE) else (echo.All FALSE)
Code: Select all
for /L %%N in (1,1,6) do (
set "true="
if "%%N"=="1" set "true=Y"
if "%%N"=="2" set "true=Y"
if "%%N"=="3" set "true=Y"
if "%%N"=="5" set "true=Y"
if defined true (echo %%N is prime) else (echo %%N is not prime)
)
1 is prime
2 is prime
3 is prime
4 is not prime
5 is prime
6 is not prime
Code: Select all
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
for /L %%N in (1,1,6) do (
call :logic_or result "%%N==1" "%%N==2" "%%N==3" "%%N==5"
if $!result!==$1 (echo %%N is prime) else (echo %%N is not prime)
)
goto :eof
:::::::::::::::::::::::::
:logic_or <resultVar> expression1 [[expr2] ... expr-n]
SETLOCAL
set logic_or.result=0
set "logic_or.resultVar=%~1"
:logic_or_loop
if "%~2"=="" goto :logic_or_end
if %~2 set logic_or.result=1
SHIFT
goto :logic_or_loop
:logic_or_end
(
ENDLOCAL
set %logic_or.resultVar%=%logic_or.result%
goto :eof
)