Author Topic: using GOTO statement!!  (Read 2900 times)

0 Members and 1 Guest are viewing this topic.

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
using GOTO statement!!
« on: February 21, 2008, 08:32:43 AM »
is using GOTO statement not recommended in c language???




« Last Edit: February 21, 2008, 09:15:27 AM by junior000 »
view my tutorials at


www.myfirstbot.blogspot.com

Offline BANE

  • Supreme Robot
  • *****
  • Posts: 639
  • Helpful? 4
  • E=roboticsC^2
Re: using GOTO statement!!
« Reply #1 on: February 21, 2008, 11:54:40 AM »
what program are you using?

bane

Offline junior000Topic starter

  • Full Member
  • ***
  • Posts: 59
  • Helpful? 0
Re: using GOTO statement!!
« Reply #2 on: February 22, 2008, 01:34:25 AM »
to jump from one loop to another
view my tutorials at


www.myfirstbot.blogspot.com

Offline Tsukubadaisei

  • Robot Overlord
  • ****
  • Posts: 293
  • Helpful? 0
Re: using GOTO statement!!
« Reply #3 on: February 22, 2008, 03:18:32 AM »
It is not recommended if you abuse it. Your code will become difficult to read and thus difficult to debug. It is called Spaghetti code.
A.I.(yes those are my initials)

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
    • Ro-Bot-X Designs
Re: using GOTO statement!!
« Reply #4 on: February 22, 2008, 04:00:10 AM »
GOTO is used to jump to a subroutine in Basic. When that subroutine ends, there is no turning back to the place the jump was called. If one needs to jump back, the GOSUB is used.

In C you can define functions and instead of GOTO or GOSUB you will just call the function. So you can have a few functions that you can call from different places in the main program. If you need to return from the place you call the function, use RETURN at the end of the function. If not, just call another function that will continue the program, or call Main function. The nice part of C is that you can return variable values at the end of the function. This way you can make a ReadSensor(s) function and return the value(s) to the Main program.
You can also group all the motors and sensors functions in a header file that you can import right at the beginning of the program, in the "#include" section.
Check out the uBotino robot controller!

 


Get Your Ad Here