Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. :: Basic Syntax
  2.  
  3. if (condition) dosomething
  4.  
  5. :: For if..else if
  6. if (condition) (statement1) else (statement2)
  7.  
  8. SET /A a=2
  9. SET /A b=3
  10. SET name1=Aston
  11. SET name2=Martin
  12.  
  13. :: Using if statement
  14. IF %a%==2 echo The value of a is 2
  15. IF %name2%==Martin echo Hi this is Martin
  16.  
  17. :: Using if else statements
  18. IF %a%==%b% (echo Numbers are equal) ELSE (echo Numbers are different)
  19. IF %name1%==%name2% (echo Name is Same) ELSE (echo Name is different)
  20. PAUSE
  21.  
  22.  
  23. :: Example to check if a variable is defined or not
  24. @echo OFF
  25.  
  26. ::If var is not defined SET var = hello
  27. IF "%var%"=="" (SET var=Hello)
  28.  
  29. :: This can be done in this way as well
  30. IF NOT DEFINED var (SET var=Hello)
  31.  
  32. :: Example to check if a file exists or not
  33.  
  34. @echo OFF
  35.  
  36. ::EXIST command is used to check for existence
  37. IF EXIST D:\abc.txt ECHO abc.txt found
  38. IF EXIST D:\xyz.txt (ECHO xyz.txt found) ELSE (ECHO xyz.txt not found)
  39.  
  40. PAUSE
  41.  
  42. @echo off
  43. setlocal enabledelayedexpansion
  44. set topic[0] = comments
  45. set topic[1] = variables
  46. set topic[2] = Arrays
  47. set topic[3] = Decision making
  48. set topic[4] = Time and date
  49. set topic[5] = Operators
  50.  
  51. for /l %%n in (0,1,5) do (
  52. echo !topic[%%n]!
  53. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement