Thursday, November 6, 2025

GOTO Statement in Batch Scripting for infinite loop

The built-in %RANDOM% environment variable and GOTO statement can be used for infinite loop.

@echo off
mode 400
color 03

:label
echo %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random% %random%
goto label

pause


Type GOTO/? in CMD window for more information as I have done:

C:\Users\ajeet> GOTO/?

Directs cmd.exe to a labeled line in a batch program.

GOTO label

The label specifies a text string used in the batch program as a label.  You type a label on a line by itself, beginning with a colon.  If Command Extensions are enabled GOTO changes as follows:  GOTO command now accepts a target label of :EOF which transfers control to the end of the current batch script file.  This is an easy way to exit a batch script file without defining a label.  Type CALL /?  for a description of extensions to the CALL command that make this feature useful.


No comments:

Post a Comment

Hot Topics