Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#1
Post
by shadeclan » 13 Oct 2011 13:08
No, I'm not talking about the one connected to your anus, moron!
In goto statements, it seems that colons are almost always optional. For example:
... seems just as valid as ...
Only in cases of the implicit label
EOF is it required:
My question is this - is there some advantage or disadvantage in colon usage? Has anyone found cases where a colon was or was not required in a goto statement?
See Ed? I still come here!
-
nitt
- Posts: 218
- Joined: 22 Apr 2011 02:43
#2
Post
by nitt » 13 Oct 2011 14:07
shadeclan wrote:No, I'm not talking about the one connected to your anus, moron!
That wasn't that funny...
And you never need the colon with tags.
AssemblyCode: Select all
org 100h
tag:
mov ah, 09h
mov dx, msg
int 21
jmp tag
C++Code: Select all
#include <iostream>
int main() {
tag:
std::cout << "hi";
goto tag;
}
Batch
Last edited by
nitt on 14 Oct 2011 17:05, edited 3 times in total.
-
Rileyh
- Posts: 147
- Joined: 01 Sep 2011 03:54
- Location: Perth, Western Australia
#3
Post
by Rileyh » 13 Oct 2011 22:34
Nitt,
There is no point in explaining the question in assembly.
org 100h
tag:
mov ah, 09h
mov dx, msg
int 21
jmp tag
And in most cases, the colon is not needed to goto a tag.
But it does not affect the capability of the code. I just use the colon out of habit.
-
!k
- Expert
- Posts: 378
- Joined: 17 Oct 2009 08:30
- Location: Russia
#4
Post
by !k » 14 Oct 2011 00:18
(is the same as) goto :a
until you do not use an editor with code coloring
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#5
Post
by shadeclan » 14 Oct 2011 08:35
nitt wrote:shadeclan wrote:No, I'm not talking about the one connected to your anus, moron!
That wasn't that funny...
Forgive the potty humor - I was trying to cut folks off "at the pass" as we say here in the US.
!k wrote:until you do not use an editor with code coloring
I, myself, use
PSPad for batch editing. It does a pretty good job of highlighting except in
two instances: indented labels, such as:
Code: Select all
:NormalLbl (normal highlighting)
...Code...
:IndentedLbl (no highlighting)
...More code...
and internal function calls, such as:
Code: Select all
call:SomeFun (Label name is not highlighted)
It handles goto statements both with and without colons. By the way Ed, it actually supports a Dutch version!
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#6
Post
by Ed Dyreen » 14 Oct 2011 11:32
shadeclan wrote:...
My question is this - is there some advantage or disadvantage in colon usage? Has anyone found cases where a colon was or was not required in a goto statement?
See Ed? I still come here!
The colon is no longer required since XP. It's still used in batches that need to be compatible !
Or was it the other way around ? Damnet
now I am confused myself, there is a difference, otherwise I wouldn't have written code like:
Code: Select all
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@rem:: Suppress all 'direct call' related errors, all Windows OSes.
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@rem::(
@ if "%$ScriptHost.FullPathFile%"=="" 2>nul goto :ENDOLDOS ()
@ if "%$ScriptHost.FullPathFile%"=="" 2>nul goto ENDOLDOS ()
@rem::)
@rem :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Code: Select all
:ENDOLDOS ()
@rem ::
@rem :: Exit 'old' OS
@rem ::
@rem ::(
@rem :: Initialize 'old' OS
@rem ::(
@ echo Off
@rem ::)
@rem :: Print reason
@rem ::(
@ echo.
@ echo. Direct call to SubRoutine not allowed ^!
@rem ::)
@rem :: Pause until user confirms
@rem ::(
@ 2>nul set "?= " <nul
@rem ::
@ pause
@rem ::)
@rem :: CLearScreen may be needed to force close on exiting an 'old' OS
@rem ::(
@ cls
@rem ::)
@rem :: OS may not support the 'exit error' command
@rem ::(
@ 2>nul exit 1
@rem ::)
@rem :: OS should support the 'goto EOF' command
@rem ::(
@ goto EOF
@rem ::)
@rem ::
goto EOF ()
@rem ::)
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#7
Post
by shadeclan » 14 Oct 2011 11:38
I was wondering when you'd show up!
Ed Dyreen wrote:now I am confused myself, there was a difference ...
Well, think about it and let me know.
-
nitt
- Posts: 218
- Joined: 22 Apr 2011 02:43
#8
Post
by nitt » 14 Oct 2011 17:02
Rileyh wrote:Nitt,
There is no point in explaining the question in assembly.
-_- Is Assembly
really the only one you noticed? Did you miss the C++ and Batch example?
My point was exactly what I said before it, that you never need to use the colon when "going to" a tag.
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#9
Post
by shadeclan » 17 Oct 2011 06:29
nitt wrote:-_- Is Assembly really the only one you noticed? Did you miss the C++ and Batch example?
Actually,
I noticed, although I am ignorant of any C language
and don't know assembly
.
Assembly has always fascinated me but I have never had the time to learn.
-
nitt
- Posts: 218
- Joined: 22 Apr 2011 02:43
#10
Post
by nitt » 17 Oct 2011 13:18
shadeclan wrote:nitt wrote:-_- Is Assembly really the only one you noticed? Did you miss the C++ and Batch example?
Actually,
I noticed, although I am ignorant of any C language
and don't know assembly
.
Assembly has always fascinated me but I have never had the time to learn.
I don't know Assembly, either. But I know a lot of it.
http://www.youtube.com/watch?v=mWeh3_ITG7M27 tutorials, and hopefully a 28th eventually, they break down all of what I know into the simplest of terms.
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#11
Post
by shadeclan » 17 Oct 2011 13:25
Nice. Thanks - I'm saving the link. Assembly appears to be a dying skill but I have great respect for those who take the time to learn and use it.
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#12
Post
by dbenham » 25 Oct 2011 16:03
(original post deleted) Never mind - I was not distinguishing between GOTO LABEL vs. CALL LABEL.
Since GOTO LABEL without the colon works, I just assumed CALL LABEL works as well. Well it doesn't.
Dave Benham
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#13
Post
by shadeclan » 26 Oct 2011 06:40
dbenham wrote:(original post deleted) Never mind - I was not distinguishing between GOTO LABEL vs. CALL LABEL.
Since GOTO LABEL without the colon works, I just assumed CALL LABEL works as well. Well it doesn't.
Dave Benham
Yup.
Just for giggles, I tried calling a label in a batch job from a different batch job, ie: [call otherbatch.bat:otherlbl] - fortunately, it didn't work. I've learned a lot about batch scripting since I started frequenting this site - I've built beautiful libraries of routines I use every day. I would have been a little upset if I'd built the interface to those libraries for nothing or if there was a way to circumvent the interface - I do some error checking there.
-
shadeclan
- Posts: 61
- Joined: 02 Jun 2011 11:29
- Location: USA - Somewhere between Albany NY and Bennington VT
#14
Post
by shadeclan » 28 Oct 2011 12:11
Here's a thought. Since in the command "goto:eof" the colon is required, wouldn't it be a good idea to always use the colon for other labels so that, if you are a sieve-mind like myself, you don't forget it when coding "goto:eof"?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#15
Post
by aGerman » 28 Oct 2011 13:46
:eof is no label. It's only a virtual expression which tells the parser to jump to the end of file. For that reason only for goto :eof needs the colon.
Regards
aGerman