Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what is the command to exit a loop in C?
#11
see? Wink more than 14,000 gotos on Linux source Tongue

The issue is not: "goto is bad", but "people don't know how to use goto properly".

Mind you.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#12
GOTO is evil???? Why?

Other ideas:

Make an exit variable:
If exit is 0 then the loop goes, but when it is 1, the loop exits.

If You need to exit in the middle of the loop, place an IF exit==0 before the unwanted code (Of course, dont forget to put that between the {})

If You have a FOR cycle, simply increase the counter to it's maximum, and the loop will exit.

Anyway, I sometimes use GOTO, but else I use these.
ingCheetah, the Running Cheetah Software programmer

http://rcs.fateback.com/
Reply
#13
To exit a loop you can use whatever you want:
Code:
#define Go_Away_off_this_darn_loop exit

in C++ defines are evil so you should do something smarter..
Big Grin
Antoni
Reply
#14
Quote:GOTO is evil???? Why?

Other ideas:

Make an exit variable:
If exit is 0 then the loop goes, but when it is 1, the loop exits.

If You need to exit in the middle of the loop, place an IF exit==0 before the unwanted code (Of course, dont forget to put that between the {})

If You have a FOR cycle, simply increase the counter to it's maximum, and the loop will exit.

Anyway, I sometimes use GOTO, but else I use these.

yeah, there are workarounds. But goto is faster and straightforward. You can exit 27 nested loops/ifs/whends/cases/whatevers in a while. No need to do 27 checks.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#15
The MINIX code I am working with has some funky goto code like this:

Code:
<In the kernel>
  rp->p_reg.pc = __sigreturn;
  rp->p_reg.npc = rp->p_reg.pc + 4;

<In the library>
  __sigreturn:
    ld [%sp + 96], %o0
    ...

It allows jumps to arbitary points in code (even to other functions) without causing a stack save, the __sigreturn function can then read info straight from the stack.
esus saves.... Passes to Moses, shoots, he scores!
Reply
#16
LooseCaboose is a genius. Listen to him. I am just to back him. Gotos are for really good, experienced programmers. They save time if used correctly. Processors are simple: they perform arithmetic operations, do memory accesses, and jump. Goto = jump. What's wrong?
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)