Author |
Message |
theanimator
|
Posted: Mon Oct 24, 2005 7:01 pm Post subject: How do you make a goto line in a program? |
|
|
I am trying to make a goto line so that when something is typed it will goto another part of the program thus allowing mutiple programs in one but being able to choose the one you want. example (incomplete)
var answer : string
beginning
put "what would you like to do?"
get answer
if answer = "start" then goto start
elsif answer = "beginning" then goto beginning
start
put "ok then let's start" |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: Mon Oct 24, 2005 7:05 pm Post subject: (No subject) |
|
|
This is not BASIC, even Turing is above that level. Think about programming logically, step by step, not that one part teleports to another. This is your first step to procedural programming!
Programs execute from top to bottom, that if statement will exit, and whatever is next will be executed, like any number of practical things.
note: You need an end if at the end of your if structure.
Look up the tutorials here for more help, and feel free to ask questions!
*edit* For particularily what you are asking, definately look up procedures/functions. |
|
|
|
|
|
Cervantes
|
Posted: Mon Oct 24, 2005 7:21 pm Post subject: (No subject) |
|
|
This might be of interest of you. But again, it's poor programming.
Moved to Turing Help. |
|
|
|
|
|
TokenHerbz
|
Posted: Mon Oct 24, 2005 10:44 pm Post subject: (No subject) |
|
|
I made somthing of a sort, does this mean im godly?? lolz
code: |
var ans: int
var b,m,e,q: boolean:= false
q:= true
proc question
loop
put"Which part do you want to skip to?"
put "1-Begining"
put "2-Middle"
put "3-End"
get ans
if ans < 4 and ans > 0 then
exit
else
cls
end if
end loop
if ans = 1 then
b:= true
m:= true
e:= true
elsif ans = 2 then
m:= true
e:= true
else
e:= true
end if
end question
loop
if q = true then
question
q:= false
end if
if b = true then
put "Begining"
b := false
end if
if m = true then
put "Middle"
m:= false
end if
if e = true then
put "End"
e:= false
q:= true
end if
end loop
|
|
|
|
|
|
|
[Gandalf]
|
Posted: Mon Oct 24, 2005 10:51 pm Post subject: (No subject) |
|
|
Really, this is much easier using procedures.
For another alternative, there should be a topic in the tutorials section - "How to Cheat the Goto Line" or something like that. |
|
|
|
|
|
TokenHerbz
|
Posted: Mon Oct 24, 2005 10:54 pm Post subject: (No subject) |
|
|
go on irc i gots a Question which i shouldn't post here for... |
|
|
|
|
|
Tony
|
Posted: Tue Oct 25, 2005 7:45 am Post subject: (No subject) |
|
|
[Gandalf] wrote: there should be a topic in the tutorials section - "How to Cheat the Goto Line" or something like that.
it's right here actually |
|
|
|
|
|
theanimator
|
Posted: Tue Oct 25, 2005 5:01 pm Post subject: (No subject) |
|
|
Thanx TokenHerbz. This really helped me with my problem. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TokenHerbz
|
Posted: Wed Oct 26, 2005 12:33 am Post subject: (No subject) |
|
|
no prob, anytime..
**smirks and looks around** |
|
|
|
|
|
[Gandalf]
|
Posted: Wed Oct 26, 2005 4:42 am Post subject: (No subject) |
|
|
Tony wrote: [Gandalf] wrote: there should be a topic in the tutorials section - "How to Cheat the Goto Line" or something like that.
it's right here actually
Eh... that's what I meant, that there already was one... blah! Should have worded it differently . |
|
|
|
|
|
codemage
|
Posted: Wed Oct 26, 2005 12:22 pm Post subject: (No subject) |
|
|
Stay away from GOTO type commands as much as possible. While they can be nice in smaller programs, they make your code really nasty, really fast.
They're considered a no-no of standard programming conventions. |
|
|
|
|
|
theanimator
|
Posted: Wed Oct 26, 2005 6:12 pm Post subject: (No subject) |
|
|
oh well, it works great in basic which is what i started with am comfortable in using, but then i get to turing and so much to learn. Oh well it takes time. |
|
|
|
|
|
codemage
|
Posted: Thu Oct 27, 2005 10:20 am Post subject: (No subject) |
|
|
It does; and BASIC was my first language as well - but BASIC is pretty much considered a 'bad' language now.
The newer incarnations (like visual basic) don't allow GOTO. It makes code less modular, and harder to trace (especially if you're not the original programmer). |
|
|
|
|
|
|