批次處理關係運算子範例

2019-10-16 22:59:36

批次處理指令碼語言支援關係運算子。以下程式碼片段顯示了如何使用關係運算子。

範例

@echo off 
SET /A a=5 
SET /A b=10 
if %a% EQU %b% echo A is equal to than B 
if %a% NEQ %b% echo A is not equal to than B 
if %a% LSS %b% echo A is less than B 
if %a% LEQ %b% echo A is less than or equal B
if %a% GTR %b% echo A is greater than B 
if %a% GEQ %b% echo A is greater than or equal to B

執行上面範例程式碼,得到以下結果 -

A is not equal to than B
A is less than B
A is less than or equal B