Merhabalar,
Bu ders, if ifadesini nasıl kullanıldığını içermektedir.. if ifadesinin genel kullanım sytax'ı aşağıdaki gibidir.
if(condition) do_something
İlk örneğimiz integer variable'ları kontrol etmek
@echo off
SET /A a=5
SET /A b=10
SET /A c=%a% + %b%
if %c% == 15 echo "The value of variable c is 15"
if %c% == 10 echo "The value of variable c is
pause
çıktı
Bu örnekte string variable kontrol etme işlemi
@echo off
SET str1=String1
SET str2=String2
if %str1% == String1 echo "The value of variable String1"
if %str2% == String3 echo "The value of variable c is String3"
pause
Çıktı:
if/else ifadesi:
If (condition) (do_something) ELSE (do_something_else)
İnteger variable'ları kontrol etme
@echo off
@echo off
SET /A a=5
SET /A b=10
SET /A c=%a% + %b%
if %c% == 15 (echo "The value of variable c is 15") else (echo "Unknown value")
if %c% == 10 (echo "The value of variable c is 10") else (echo "Unknown value")
pause
Çıktı:
if defined ifadesi:
if defined some variable some command
@echo off
SET
str1=String1
SET str2=String2
if defined str1 echo "Variable str1 is defined"
if defined str3 (echo "Variable str3 is defined") else (echo "Variable str3 is
not defined")
pause
Çıktı:
if exist ifadesi
If exist somefile.ext do_something
@echo off
if exist C:\set3.txt (echo "File exists") else (echo "File does not exist")
pause
Çıktı:
Nested If Statements
if(condition1) if (condition2) do_something
@echo off
SET /A a=5
SET /A b=10
if %a% == 5 if %b% == 10 echo "The value of the variables are correct"
pause
Çıktı:
if goto statement
@echo off
SET /A a=5
SET /A b=10
if %a% == 5 goto :labela
if %b% == 10 goto :labelb
:labela
echo "The value of a is 5"
:labelb
echo "The value of a is 10"
pause
Çıktı:
1 Mayıs 2017 Pazartesi
Batch Programlama if statements

Şükrü ERGÜNTOP
Author & Editor
Bilecik Şeyh Edebali Üniversitesi Bilgisayar Mühendisi mezunuyum 2015 yılından beri Sigorta Bilgi ve Gözetim Merkezinde İş Zekası alanında çalışmaktayım
05:57
.Bat programlama
Kaydol:
Kayıt Yorumları (Atom)
0 yorum:
Yorum Gönder