Batch While Loop




Introduction: Batch While Loop

It's a simple function in batch although being very helpful

replace anything with your preferred function, title, etc that is surrounded by *


set /a Var -= 1

*echo task goes here*

if %*Var*% GTR 0 goto *your_title*

you must change "your_title" to the same thing

any other things you are having trouble on and need help just ask

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Virus

disclaimer: I am not responsible for any stupid actions you preform with these viruses

you could make a "virus"


start cmd.exe

goto *your_title*

pretty nasty mostly because no admin authority required

I would install it on a flash drive so you can just pull it out and terminate the program more civilized and useful

@echo off

color 0a



echo enter a option

echo 1. open 10

echo 2. open 25

echo 3. open 50

echo 4. open 100

echo 5. open 500

echo 6. open 1000

echo 7. open 5000

echo 8. open 10000

set /p choice=

if %choice%==1 set countfiles= 10

if %choice%==2 set countfiles= 25

if %choice%==3 set countfiles= 50

if %choice%==4 set countfiles= 100

if %choice%==5 set countfiles= 500

if %choice%==6 set countfiles= 1000

if %choice%==7 set countfiles= 5000

if %choice%==8 set countfiles= 10000

:loop set /a countfiles -= 1 start cmd.exe

if %countfiles% GTR 0 goto loop


goto select

and if you want to enter a amount this one is the one for you

@echo off

color 0a

echo how many

set /p countfiles=


set /a "countfiles-=1"

start cmd.exe

if %countfiles% GTR 0 goto loop


like I said already if you have any questions about batch ask

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020