Function is a group of statements used to perform a task.
How to define a function?
A function is Defined by using the label statement.
Syntax
:function_name
Do_something
GOTO :EOF
GOTO :EOF
Transfers the control to the end of Batch file.
Hello.bat
@ECHO OFF
REM Call main function
GOTO :main
REM Defining a function that prints "Hello World"
:sayHello
ECHO Hello World
GOTO :EOF
REM Defining a function that prints "Good Morning"
:sayGoodMorning
ECHO Good Morning
GOTO :EOF
:main
CALL :sayHello
CALL :sayGoodMorning
ECHO Done....
GOTO :EOF
C:\Users\Public>Hello
Hello World
Good Morning
Done....
As you see Hello.bat file, I defined 3 functions.
a. sayHello
b. sayGoodMorning
c. main
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here