Goto %loop%

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sklub
Posts: 9
Joined: 13 Jan 2017 12:56

Goto %loop%

#1 Post by sklub » 13 Jan 2017 13:03

Code: Select all

:top
set loop=:top
goto %loop%


does anyone use this ?
Last edited by Squashman on 13 Jan 2017 13:17, edited 1 time in total.
Reason: MOD EDIT: Please use code tags.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Goto %loop%

#2 Post by Squashman » 13 Jan 2017 13:18

sklub wrote:

Code: Select all

:top
set loop=:top
goto %loop%


does anyone use this ?

Why would anyone use this code?

sklub
Posts: 9
Joined: 13 Jan 2017 12:56

Re: Goto %loop%

#3 Post by sklub » 13 Jan 2017 13:32

not the script itself thats garbage for the garbage can.
but im looking for usefull fuction to implement a goto %loop% function...
does any one know any good use for this,because so far ive only been replacing it with real loops.

Cornbeetle
Posts: 31
Joined: 23 Nov 2015 09:34

Re: Goto %loop%

#4 Post by Cornbeetle » 13 Jan 2017 13:48

Not sure why you would need to do this.

Code: Select all

set label=:top

:top
set /a num+=1
echo %num%
goto %label%

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Goto %loop%

#5 Post by npocmaka_ » 13 Jan 2017 13:48

as FOR /L hangs with big numbers goto loop sometimes is the only way to use iteration loops: http://www.dostips.com/forum/viewtopic.php?t=3487

though it should be used rarely as it hits the performance.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Goto %loop%

#6 Post by Aacini » 13 Jan 2017 15:15

The simplest example of a similar code is this:

Code: Select all

choice /C ABC /M "Enter desired option: "
goto option-%errorlevel%

:option-1  A


:option-2  B

etc...

Antonio

Aspidiske
Posts: 7
Joined: 30 Oct 2016 09:48

Re: Goto %loop%

#7 Post by Aspidiske » 14 Jan 2017 08:25

goto as variable already used as following:

This allows you to invert the sequence between programming sets

Code: Select all

@echo off
set exitprogram1=program3
set exitprogram3=program2
set exitprogram2=completed
goto program1
rem -------------------------------1
:program1
echo.1
goto %exitprogram1%
rem -------------------------------2
:program2
echo.2
goto %exitprogram2%
rem -------------------------------3
:program3
echo.3
goto %exitprogram3%
:completed
pause

sklub
Posts: 9
Joined: 13 Jan 2017 12:56

Re: Goto %loop%

#8 Post by sklub » 15 Jan 2017 15:52

Well im just messing around with scripts Learning in the process...Thanks for the posts

Post Reply