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

F

faizankhan666

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.
 
M

Moonlit

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
 
J

Jim Langston

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
 
S

Simon G Best

Hello!

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
 
F

faizankhan666

Moonlit said:
Hi,

In C/C++

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


I tried :

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

Bo Persson

I tried :

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

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
 
P

Phlip

Bo said:
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.
 
M

Moonlit

Hi,

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

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
 
N

noone

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.
 
R

red floyd

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/
 
N

noone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top