By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,128 Members | 926 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,128 IT Pros & Developers. It's quick & easy.

How to use goto command in visual basic c++ ?

P: n/a
I have been given a project to prepare a program for cricket
scoreboard...now when all the 10 wickets fall I want my program to go
to the end..lets say on line 50.
what is the syntax of goto statement....plz give me a mini example for
it if u can.
thanx.

Dec 30 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Hi,

In C/C++

goto _Label1;
break;
}
_State = 1;
return eQuickSaveGame;
_Label1:
return eFinished;
}

However I assume you actually mean Visual Basic,
From msdn (you could have done a search yourself, you know):

Sub gotoStatementDemo()
Dim number As Integer = 1
Dim sampleString As String
' Evaluate number and branch to appropriate label.
If number = 1 Then GoTo Line1 Else GoTo Line2
Line1:
sampleString = "Number equals 1"
GoTo LastLine
Line2:
' The following statement never gets executed because number = 1.
sampleString = "Number equals 2"
LastLine:
' Write "Number equals 1" in the Debug window.
Debug.WriteLine(sampleString)
End Sub

Regards, Ron AF Greve

http://moonlit.xs4all.nl

"fa***********@hotmail.com" <fa***********@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
>I have been given a project to prepare a program for cricket
scoreboard...now when all the 10 wickets fall I want my program to go
to the end..lets say on line 50.
what is the syntax of goto statement....plz give me a mini example for
it if u can.
thanx.

Dec 30 '06 #2

P: n/a
"fa***********@hotmail.com" <fa***********@gmail.comwrote in message
news:11**********************@48g2000cwx.googlegro ups.com...
>I have been given a project to prepare a program for cricket
scoreboard...now when all the 10 wickets fall I want my program to go
to the end..lets say on line 50.
what is the syntax of goto statement....plz give me a mini example for
it if u can.
thanx.
You will thank yourself if you forget the goto statement even exists. The
goto stratment does not belong in a structured langague. There are very
rare exceptions when using a goto actually make sense, but if you look at
any professional code you shouldn't even see a goto statement.

When all the 10 wickets fall, return. Exit. Set a flag. Anything but use a
goto :D
Dec 30 '06 #3

P: n/a
Hello!

fa***********@hotmail.com wrote:
I have been given a project to prepare a program for cricket
scoreboard...now when all the 10 wickets fall I want my program to go
to the end..lets say on line 50.
what is the syntax of goto statement....plz give me a mini example for
it if u can.
thanx.
Goto is Evil. (Look Evil up in the FAQ.) Goto is Very Evil. Goto is
very good for writing spaghetti code with.

Simon

--
What happens if I mention Leader Kibo in my .signature?
Dec 30 '06 #4

P: n/a

Moonlit wrote:
Hi,

In C/C++

goto _Label1;
break;
}
_State = 1;
return eQuickSaveGame;
_Label1:
return eFinished;
}

I tried :

goto end;
----//some statements//
---
--

end;

error="end" undeclared identifier"

Dec 30 '06 #5

P: n/a
fa***********@hotmail.com wrote:
Moonlit wrote:
>Hi,

In C/C++

goto _Label1;
break;
}
_State = 1;
return eQuickSaveGame;
_Label1:
return eFinished;
}


I tried :

goto end;
----//some statements//
---
----//some statements//
---
---

end;
Yes, this should be

end: ;
error="end" undeclared identifier"
The target label for a goto must end in a colon.

One problem with goto is that the goto statement doesn't show where you
actually go. The placement of the target label decides that. If that is
moved somewhere else, the effect changes.

If you have a lot of gotos and labels in your program, you will soon lose
the control over them and not know really what your program does (or how it
does it). Therefore, most programmers try to avoid using gotos whenever
possible. Having one or two isn't really that dangerous, but having lots of
them is!
Bo Persson
Dec 30 '06 #6

P: n/a
Bo Persson wrote:
If you have a lot of gotos and labels in your program, you will soon lose
the control over them and not know really what your program does (or how
it does it). Therefore, most programmers try to avoid using gotos whenever
possible. Having one or two isn't really that dangerous, but having lots
of them is!
As usual for a thread on the perils of goto, the ultimate answer is short
functions, where control-flow is less precarious.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Dec 30 '06 #7

P: n/a
Hi,

"Phlip" <ph******@yahoo.comwrote in message
news:ec******************@newssvr23.news.prodigy.n et...
Bo Persson wrote:
>If you have a lot of gotos and labels in your program, you will soon lose
the control over them and not know really what your program does (or how
it does it). Therefore, most programmers try to avoid using gotos
whenever possible. Having one or two isn't really that dangerous, but
having lots of them is!

As usual for a thread on the perils of goto, the ultimate answer is short
functions, where control-flow is less precarious.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!

All very true.

For the OP. Note also that I never actually use goto's. The piece posted was
something generated by a precompiler I am writing I need goto's there to
simulate multitasking. For instance a while loop in the high level language
is translated into an 'if then goto' over the end of the block and a
unconditional goto to the beginning. Just at the end I remember the label
and return from the function so other threads can run. on entry I jump to
the 'remembered label'.

So goto's are needed but I never have used them in regular code.
Regards, Ron AF Greve

http://moonlit.xs4all.nl
Dec 30 '06 #8

P: n/a
On Sat, 30 Dec 2006 21:45:47 +0100, Moonlit wrote:
>
All very true.

For the OP. Note also that I never actually use goto's. The piece posted
was something generated by a precompiler I am writing I need goto's there
to simulate multitasking. For instance a while loop in the high level
language is translated into an 'if then goto' over the end of the block
and a unconditional goto to the beginning. Just at the end I remember the
label and return from the function so other threads can run. on entry I
jump to the 'remembered label'.

So goto's are needed but I never have used them in regular code.
Good point...I believe Nicholos Wirth wrote a book a long time ago "GOTOS:
considered harmful" outlining the dangers of spaghetti code. Unfortunately
the modern computer science crowd often fail to understand lower level
computer programming like ASM and machine code, where all higher level
flow control loops degenerate to include conditional and unconditional
gotos/jumps.

I myself have been chastised for suggesting that most computer programs
cannot work without gotos...because they didn't understand what I was
really saying.

Dec 31 '06 #9

P: n/a
noone wrote:
On Sat, 30 Dec 2006 21:45:47 +0100, Moonlit wrote:
Good point...I believe Nicholos Wirth wrote a book a long time ago "GOTOS:
considered harmful" outlining the dangers of spaghetti code.
It was Edsger Dijsktra, in a 1968 article in /Communications of the ACM/
Dec 31 '06 #10

P: n/a
Goto is Evil. (Look Evil up in the FAQ.) Goto is Very Evil. Goto is very good for writing spaghetti code with.

If you are using goto's, you should also use comefrom's.
http://en.wikipedia.org/wiki/COMEFROM

Lynn
Dec 31 '06 #11

P: n/a
Lynn wrote:
>Goto is Evil. (Look Evil up in the FAQ.) Goto is Very Evil. Goto is very good for writing spaghetti code with.

If you are using goto's, you should also use comefrom's.
http://en.wikipedia.org/wiki/COMEFROM
Thanks for posting that link. I liked that.

:-)

Simon

--
What happens if I mention Leader Kibo in my .signature?
Dec 31 '06 #12

P: n/a
On Sat, 30 Dec 2006 20:29:38 -0800, red floyd wrote:
noone wrote:
>On Sat, 30 Dec 2006 21:45:47 +0100, Moonlit wrote:
>Good point...I believe Nicholos Wirth wrote a book a long time ago
"GOTOS: considered harmful" outlining the dangers of spaghetti code.

It was Edsger Dijsktra, in a 1968 article in /Communications of the ACM/
I guess my source was mistaken:

"Real Programmers Don't Use Pascal". Datamation, July 1983.

:^P
Dec 31 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.