Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

equivalent "break" keyword

lets say we have

for i = 1 to 5
if condition then
//I wanna jump to next iteration,
Next i


  • A very similar question led to a lively discussion on the WORKS forum about two years ago. The original poster was asking how to emulate continue|break syntax in BASIC+, much as you are.

    I offered one solution using a GoTo label (although I'm normally anti-GoTo):
    Log = '' a = 1 Loop if a >= 5 AND a <= 6 then a += 1 Goto Continue end Log := 'a = ' : a : @FM a += 1 Continue: Until a = 20 Repeat Log[-1, 1] = ''
    Bob Carten offered a solution using the Case statement:
    done = false$ loop readnext k begin case case <cond1> done =1 case <cond2> * CONTINUE case otherwise$ < do more stuff> end case until done repeat
  • for i = 1 to 5 if condition else // do my stuff? end Next i

  • @AusMarkB yes, and I don't want to place existing contents(very very long) between if statement and then format
  • IMHO, I'm strongly in favour of Mark or Bob's structure as best practise. Any very lengthy code within a block structure should be taken out as its own subroutine or service module, leaving the conditional or loop structure clear and concise.
    I'll avoid any Gotos, breaks, or even premature Returns within block, like the plaque! (Probably because I was trained way back to deduct marks on student 101 assignments for doing that kind of stuff ;)
  • edited March 2019
    for i = 1 to 5 if needToJumpToNextIteration else GoSub do_my_stuff end Next i
  • Honestly, the original thread in the Revelation forum was trying to achieve similar syntax and functionality. If it was just functionality I would do what others have suggested (and what I do anyway). Like M@, I'm violently opposed to GoTos. However, the syntax is a little unique and BASIC+ doesn't support it but my GoTo came close. See this page.
  • With an emphasis on syntax and your example link, I see how that changes the question and therefore the answer and yes I picked up on the "I wouldn't do this myself but this is how you might" tone.

    I'm not convinced that familiar syntax is a reasonable motive for ignoring good practice. Perhaps that's why the original OI forum post was so lively.
Sign In or Register to comment.