0

What is correct syntax for goto : line number?

while programming sometimes one needs to tell the program to return and start from line number .. It seemes that it should be : goto -> line .. but practically it does not work as i have experienced . Please help

18th Dec 2016, 9:43 AM
irajjs
irajjs - avatar
7 Antworten
+ 2
#include <iostream> using namespace std; int main() { int x=3; x: //this tells the compiler to come here cout<<++x; if(x<10) goto x; //this is command statement return 0; } This is the use of goto statement.
18th Dec 2016, 10:04 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 1
In any case, the use of the goto statement is not recommended. Use functions and cycles.
18th Dec 2016, 4:28 PM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
+ 1
The thing is, its an abstraction. Programs dont keep track of lines.. We use lines to fit code into our view field, it is all one continuous "line" to the program. So that is why it is as Rishabh Agrawal explains.
18th Dec 2016, 5:43 PM
kddavidson
kddavidson - avatar
0
Thank you Rishabh but i need to know how to tell my program to go back to an specific line to start from that line again
18th Dec 2016, 10:33 AM
irajjs
irajjs - avatar
0
irajjs, it's not possible
18th Dec 2016, 10:39 AM
Vladimir Honcharenko
Vladimir Honcharenko - avatar
0
I do not remember exactly but l think i have seen that in some other source codes
18th Dec 2016, 4:19 PM
irajjs
irajjs - avatar
0
I think if progams can align a text and if they can show line numbers then they should be able to recognize the lines themselves!!
18th Dec 2016, 9:35 PM
irajjs
irajjs - avatar