Author Topic: Feature request - Exit Case/Break  (Read 8654 times)

0 Members and 1 Guest are viewing this topic.

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #15 on: September 07, 2020, 03:58:22 am »
Wow, if only all my threads got such a response!

Anyway, I only asked cause I came across the need for it, admittedly it's only the once in 10 years of coding in QB64 i've had this need though so i suppose i could just use a work around.

Here's a basic view of how i came across the need for _BREAK. I had a select case with a triple For loop in it and rather than the work around of checking a variable and then exiting each for loop i needed a _BREAK.

Code: QB64: [Select]
  1.  
  2.   CASE 1
  3.     FOR k% = 0 TO 10
  4.  
  5.       FOR j% = 0 TO 10
  6.  
  7.         FOR i% = 0 TO 10
  8.  
  9.           if K% = Col% and j% = row% and i% = i& then _BREAK
  10.  
  11.         NEXT
  12.  
  13.       NEXT
  14.  
  15.     NEXT
  16.  

Obviously i could use Line labels and a GOTO (and is what i ended up doing) but thats not (as far as i am concerned) good coding practice, that maybe just a hangup i have being a OOP guy or something, i dunno.

I dont mind if the answers a NO as it's far from essential.

Unseen

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #16 on: September 07, 2020, 10:17:37 am »
This topic touches on a How To question for me.  If you have a Select Case within a Do Loop and you want to code one of those Cases to get you out of the Selection process and back into the Do Loop does _Continue do that? or does _Continue just skip the Case it's found in a moves onto the next Case?

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #17 on: September 07, 2020, 10:23:18 am »
_CONTINUE goes to the beginning the loop, regardless of whether you're inside a select case block or not.

That, of course, if the condition for looping is still true. Otherwise, the loop block is exited.
« Last Edit: September 07, 2020, 10:34:49 am by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #18 on: September 07, 2020, 10:38:47 am »
Steve's remarks considered, I believe we're aiming for EXIT SELECT and EXIT CASE, for when EVERYCASE is used. Does anybody have anything else to add?
« Last Edit: September 07, 2020, 01:13:08 pm by FellippeHeitor »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #19 on: September 07, 2020, 01:07:47 pm »
I'm afraid I must disagree.

My argument is we already have a way, however despise-able it is, to jump around in a program.

This would be nothing more than an alias of GOTO.

btw what is wrong with this exactly?
Code: QB64: [Select]
  1.     SELECT CASE i&
  2.      
  3.       CASE 1
  4.         FOR k% = 0 TO 10
  5.      
  6.           FOR j% = 0 TO 10
  7.      
  8.             FOR i% = 0 TO 10
  9.      
  10.               IF K% = Col% AND j% = row% AND i% = i& THEN MatchFlag%% = -1: i% = 11: j% = 11: k% = 11
  11.      
  12.             NEXT
  13.      
  14.           NEXT
  15.      
  16.         NEXT
  17.      
  18.     END SELECT
« Last Edit: September 07, 2020, 01:16:17 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #20 on: September 07, 2020, 01:14:29 pm »
The good thing is that there's no new keyword added to the language. Just a new way to use them, which won't hurt anyone at all.

My point when I ask if anyone has anything to add at this point is anything technical regarding the implementation as it's been showcased above.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #21 on: September 07, 2020, 01:19:30 pm »
Yes sounds very good to me, just extending where you can apply EXIT, no new keywords.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Feature request - Exit Case/Break
« Reply #22 on: September 07, 2020, 01:51:48 pm »
The good thing is that there's no new keyword added to the language. Just a new way to use them, which won't hurt anyone at all.

My point when I ask if anyone has anything to add at this point is anything technical regarding the implementation as it's been showcased above.

Only technical point is to be careful of flow into a CASE ELSE block of a SELECT EVERYCASE.  Make certain it’s working as intended.

As long as we’re implementing this, can we also get an EXIT <counter> command?

FOR I
   FOR J
       FOR K
           EXIT 2
       NEXT
   NEXT
NEXT

The above would exit 2 control blocks (K and J blocks) and flow down into the I block, after that 2nd NEXT.

Or maybe an EXIT TO label statement?  That could be useful too.


FOR I
   FOR J
       FOR K
           EXIT TO foo
       NEXT
   NEXT
foo:
NEXT
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #23 on: September 07, 2020, 01:56:17 pm »
Anyone willing to test the new feature, please head to the development build page and get the latest version:

https://www.qb64.org/portal/development-build/

EXIT SELECT
Can be used to exit a SELECT CASE block.

EXIT CASE
Has the same purpose of EXIT SELECT, unless when used in a SELECT EVERYCASE block. In such case, it'll skip to the next CASE evaluation.

Please try to break it. I'll be watching this thread.

PS: Anyone new to development builds, here's the changelog since v1.4 was released: https://www.qb64.org/portal/development-build-changelog/
« Last Edit: September 07, 2020, 02:08:02 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #24 on: September 07, 2020, 01:57:16 pm »
As long as we’re implementing this, can we also get an EXIT <counter> command?

I wouldn't oppose you implement it.

Quote
Or maybe an EXIT TO label statement?  That could be useful too.


FOR I
   FOR J
       FOR K
           EXIT TO foo
       NEXT
   NEXT
foo:
NEXT

But this is definitely a GOTO.
« Last Edit: September 07, 2020, 02:13:46 pm by FellippeHeitor »

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #25 on: September 07, 2020, 03:16:17 pm »
Quote
https://www.qb64.org/portal/development-build-changelog/

I couldnt see the _IFNOTINCLUDED function i previously requested here https://www.qb64.org/forum/index.php?topic=2733.msg119540#msg119540

Did this not get implemented? Is it in the works?

Thanks for putting this together though, now i've just gotta figure out what it was i was coding when i needed it!

Unseen

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #26 on: September 07, 2020, 03:22:23 pm »
The trick to check if a precompiler setting is undefined was already there. You just didn't know about it. Have you started using it for your libraries?
« Last Edit: September 07, 2020, 05:18:56 pm by FellippeHeitor »

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: Feature request - Exit Case/Break
« Reply #27 on: September 08, 2020, 10:21:20 pm »
Trying to "break"  exit case

Code: QB64: [Select]
  1.  
  2. a$ = CHR$(0)
  3.     CASE CHR$(0):
  4.         'EXIT SELECT
  5.         : EXIT CASE
  6.     CASE CHR$(1)
  7.         BEEP: BEEP
  8.     CASE ELSE
  9.         BEEP: BEEP: BEEP: BEEP: BEEP
  10.  
  11.  

using Dev version f3b92c3  Windows 10 x64

I thought 3 x BEEP was to be the result.


HOWEVER




Code: QB64: [Select]
  1. a$ = CHR$(0)
  2.     CASE CHR$(0):
  3.         'EXIT SELECT
  4.         : EXIT CASE
  5.     CASE CHR$(1)
  6.         BEEP: BEEP
  7.     CASE CHR$(0)
  8.         BEEP:
  9.     CASE ELSE
  10.         BEEP: BEEP: BEEP: BEEP: BEEP
  11.  
  12.  

gives 2 x BEEP which is logically correct.



« Last Edit: September 08, 2020, 10:31:12 pm by Richard »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Feature request - Exit Case/Break
« Reply #28 on: September 08, 2020, 10:28:54 pm »
Trying to "break"  exit case

Code: QB64: [Select]
  1.  
  2. a$ = CHR$(0)
  3.     CASE CHR$(0):
  4.         'EXIT SELECT
  5.         : EXIT CASE
  6.     CASE CHR$(1)
  7.         BEEP: BEEP
  8.     CASE ELSE
  9.         BEEP: BEEP: BEEP: BEEP: BEEP
  10.  
  11.  

using Dev version f3b92c3  Windows 10 x64

I thought 3 x BEEPS was to be the result.

Shouldn’t it be a single beep?  The first case is the only one that matches, and it doesn’t beep.  The only beep that I’d think should be triggered, is the one after the END SELECT.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Feature request - Exit Case/Break
« Reply #29 on: September 09, 2020, 09:30:43 am »
Code: QB64: [Select]
  1.  
  2. a$ = CHR$(0)
  3.     CASE CHR$(0):
  4.         'EXIT SELECT
  5.         : EXIT CASE
  6.     CASE CHR$(1)
  7.         BEEP: BEEP
  8.     CASE ELSE
  9.         BEEP: BEEP: BEEP: BEEP: BEEP
  10.  
  11.  

The above beeps once.

Code: QB64: [Select]
  1. a$ = CHR$(0)
  2.     CASE CHR$(0):
  3.         'EXIT SELECT
  4.         : EXIT CASE
  5.     CASE CHR$(1)
  6.         BEEP: BEEP
  7.     CASE CHR$(0)
  8.         BEEP:
  9.     CASE ELSE
  10.         BEEP: BEEP: BEEP: BEEP: BEEP
  11.  
  12.  

The above beeps twice.

All as expected so far.