|
C++ Label and goto
|
|
01-03-2010, 03:08 AM
Post: #1
|
|||
|
|||
|
C++ Label and goto
This is pretty the same as using labels and goto in Batch file or in Pascal.
You just need to declare where label is and to put goto on a place where you want to jump to the label. Syntax of label is : Code: name_of_the_label:Code: goto name_of_the_label;Now let's make a small example : Code: # include <iostream>Code: This is the first lineNow let's make something that can be useful. For example if you need to enter a number bigger than zero (positive number) and you want to do it with label and goto. Of course that you can do it with while, but this can be used too. So here is the code : Code: # include <iostream>Code: # include <iostream>Another task would be looping with label and goto. Let's make a program for writing numbers from 1 to n : Code: # include <iostream>I think that is everything taht you need to know about labels and goto. Hope that you like this small tut ! There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
01-10-2010, 03:26 PM
(This post was last modified: 01-10-2010 03:29 PM by PoZHx.)
Post: #2
|
|||
|
|||
RE: C++ Label and goto
(01-03-2010 03:08 AM)drdebcol Wrote: Hi, Few suggestions: Avoid using GOTO Endl is not needed just use \n why are you using an signed number if you want postives only? unsigned is for postives only signed is for postive/negatives (if you dont define it will use signed by default) Here example for you: Code: #include <iostream> |
|||
|
01-10-2010, 03:28 PM
Post: #3
|
|||
|
|||
|
RE: C++ Label and goto
Yea goto statement in large programs make the programs hard to read and maintain.
|
|||
|
01-10-2010, 10:45 PM
Post: #4
|
|||
|
|||
|
RE: C++ Label and goto
Very good. That was just an example, but i like your reply. Using break and continue is good. And i usually avoid using goto and label, this was just an explanation in case i use it !
There's a fine line between genius and insanity. I have erased this line. Oscar Levant There's a fine line between an administrator and black hat hacker. I have erased this line. Dr DEBCOL |
|||
|
« Next Oldest | Next Newest »
|





