Can I jump from one line to another in a code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can I jump from one line to another in a code?

i was trying a basic calculator and I wanted to jump to the initial line to continue the code until the user wants..I couldn't do that with continue function so I was wondering if there is a way to jump through lines. you can check the code I worte by checking my profile and give you feedbacks as well. tq.

4th Jan 2017, 6:02 PM
Aadarsha Chhetri
Aadarsha Chhetri - avatar
7 Answers
+ 7
You don't want to use goto, in languages like c# you can use functions like switch cases. Generally you should program in a manner that doesn't require jumps.
4th Jan 2017, 6:18 PM
Alex
Alex - avatar
+ 2
You don't want to do this. Many languages have a "goto" that acts like this but it makes your code more unreadable and it's just a bad idea. Make functions and use loops. There's no reason you should ever have to use jumps.
4th Jan 2017, 6:12 PM
James Durand
James Durand - avatar
+ 1
why jump make functions and use that in a way which works like adding nos by using function then call again to input no
4th Jan 2017, 7:08 PM
Sandeep Chatterjee
+ 1
As others have said, use loops. Maybe you need to start your code with a while statement.
5th Jan 2017, 12:18 AM
Alan Harrison
Alan Harrison - avatar
+ 1
I've revamped your code, when possible tell me what you think. It's on my page
21st Jan 2017, 1:34 PM
Brandon j
Brandon j - avatar
+ 1
in case you are wondering, some of the bugs that come from old fashioned GOTO statements (where code states that after this line of code you run from a specific line number) are: if you add a line of code any where other than the end, every line after must have it's line number incremented - this means if you add a line at the top - even a comment, every single GOTO now points to the wrong line of code, so now you'd have to go and change all your gotos and if you miss one you have a bug similar havoc if you move a block of code around you also have to be absolutely sure that you don't GOTO between a variable declaration and its usage eg: 1) if input()=="ABC" : 2) goto(4) 3) myVar = 123 4) print("hello") 5) print(myVar) when the input is "ABC" the program skips line 3 so never sets myVar and line 5 will throw an error about the variable not existing yet
26th Jan 2017, 3:42 AM
Phil
Phil - avatar
0
Basically the goto used programs are considered as bad programming habbit and it's better to use functions when you want to do something else in between and just call that functions .
20th Jan 2017, 6:18 PM
AVINASH TIWARI
AVINASH TIWARI - avatar