Half a croissant, on a plate, with a sign in front of it saying '50c'
h a l f b a k e r y
A dish best served not.

idea: add, search, annotate, link, view, overview, recent, by name, random

meta: news, help, about, links, report a problem

account: browse anonymously, or get an account and write.

user:
pass:
register,


                                 

Please log in.
Before you can vote, you need to register. Please log in or create an account.

breakbreak; breakbreakbreak;

New keyword to break out of lots of loops.
  (-1)
(-1)
  [vote for,
against]

If you really nest deeply into loops, sometimes you just want to get out of them. So this introduces two new keywords

breakbreak; and breakbreakbreak;

These break out of two and three loops

They can be combined as they support the + operator.

breakbreak+breakbreak; and breakbreakbreak+breakbreak;

will break out of four and five loops at once.

mylodon, Apr 04 2019

Nim Break Statement https://nim-lang.or...nts-break-statement
[Cuit_au_Four, Apr 04 2019]

[link]






       What language is this in? Also, why can't you just have a command that breaks out of all the loops currently running?
MaxwellBuchanan, Apr 04 2019
  

       Already baked.   

       Some languages allow you to jump to a label. C provides the goto statement to let you jump wherever you want in the function. In Nim, the break statement can be passed a label to specify which block to break out of.
Cuit_au_Four, Apr 04 2019
  

       // C provides the goto statement //   

       True, but its actual use - other as an example of How Not To Program - is punishable by death (for a first offence).
8th of 7, Apr 04 2019
  

       I've never understood why people are so averse to GOTO. I mean apart from the obvious problem of code followability.
MaxwellBuchanan, Apr 04 2019
  

       I don't want to specify al label, where i'm breaking out of.   

       it's the equivalent of ending up on the bad side of youtube when you just want to go BACK and you don't care where to. Just BACK or BACK BACK if that's not enough. Just to get away.
mylodon, Apr 04 2019
  

       In that case, you don't want 'break' - you want 'brexit' ...
8th of 7, Apr 04 2019
  

       Nonono. That would take forfuckingever.
MaxwellBuchanan, Apr 04 2019
  

       Some languages have this already (such as PHP) using a simpler syntax: break 3; will break out of 3 nested loops.   

       In C, breaking out of nested loops is a perfectly legitimate use of goto. Some people go to great lengths to avoid using goto, sometimes to such an extreme that their code ends up looking much messier than it would have been.   

       A slightly less controversial approach is to stick your loops in a subroutine, and return from it when you want to break.
mitxela, Apr 04 2019
  

       zzzzzzzzzzzzzz
xenzag, Apr 05 2019
  

       [+]ish...   

       It really wouldn't take much work to write a simple function, say 'break(n)' where 'n' is the number of stack entries to be unwound. I think C lets you do it explicitly (check out 'set jmp')
FlyingToaster, Apr 05 2019
  

       'Breaker... breaker...219...'
RayfordSteele, Apr 05 2019
  

       The reason this is a bad idea is that it betrays an uncertainty over flow.
theircompetitor, Apr 05 2019
  

       The only thing wrong with goto is that bad programmers use it. That's a good reason, but still insufficient to make a rule absolutely forbidding it. I've had cases where a goto would have literally saved me 40 lines of code.
Voice, Apr 05 2019
  

       I think this is an object lesson as to why you should not code or visit web pages while sipping gin.
mylodon, Apr 05 2019
  

       Indeed; a mug of Red Bull with a couple of nicotine patches dropped in it is much more ... stimulating. Until the tachycardia disabled you, that is.   

       We offer in evidence an example of doubtful coding from the early years of 8-bit microprocessors.   

       Tasked with writing an auto-ranging routine for a switched-gain electrometer amplifier, an electronic engineer and self-taught assembly language programmer adopted an eccentric solution.   

       This consisted of making the autoranging routine recursive, but incorporating a "depth counter". If the recursion cot too "deep" (for the 8-bit pointer, exceeding 0xFC), the "error handler" would search down the processor's stack (not by POP/PUSH - that would be too boringly conventional - but by indexed addressing the relevant RAM page directly) and identify the return address for the module until it found data that wasn't a return address.   

       Then it would alter the processor stack pointer to that location, PUSH the address of the amplifier zero-calibration routine onto the stack, reset the CPU flags register and execute an RTS.   

       Some sort of GOTO would probably have been preferable. We wish to express our sincere hope that the author of the code is still alive, but not well. In fact, he ought to be suffering from an excruciatingly painful, debilitating, disfiguring and humiliating medical condition, for which there is no cure and not even an effective palliative treatment. Rather like his code, actually.
8th of 7, Apr 05 2019
  
      
[annotate]
  


 

back: main index

business  computer  culture  fashion  food  halfbakery  home  other  product  public  science  sport  vehicle