[Implemented] break and continue

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

[Implemented] break and continue

Post by matthew180 »

Greetings,

I'd love to have break and continue added to PB, after the new variable types of course! ;-)

Anyone else miss having break and continue?

Matthew
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

*raises hand*

I do :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: break and continue

Post by GPI »

Have you see the "onError"-Library?

Or what do you mean

Look also for "callDebugger"

GPI
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Post by Fenix »

@GPI: I think he´s talking about select/case...



Fenix
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

@GPI: I think he´s talking about select/case...
Yes, and in (for/while) loops :)
--Kale

Image
matthew180
User
User
Posts: 64
Joined: Mon Jun 30, 2003 5:36 pm
Location: Michigan
Contact:

Post by matthew180 »

Yes, 'break' and 'continue' in reference to looping control structures, for example:

The 'break' statement terminates the execution of the nearest enclosing loop or conditional statement in which it appears. Control passes to the statement that follows the terminated statement, if any.

Code: Select all

  for i = 1 to 100
    if somecondition(i) = 1
      break
    endif
  next
In this example, lets say I want to know what the value that 'i' was when the condition became true, and at that point I also want to terminate the loop. Currently to achieve this you have to do something like this:

Code: Select all

  for i = 1 to 100
    if somecondition(i) = 1
      i_val = i
      i = 100
    endif
  next
The 'continue' statement passes control to the next iteration of the repeat, for, or while statement in which it appears, bypassing any remaining statements in the repeat, for, or while statement body. A typical use of the 'continue' statement is to return to the start of a loop from within a deeply nested loop.

Code: Select all

while i > 0
  i - 1
  x = f( i )
  if x = 1
    continue
  y + x * x
wend
Also, in other languages (C, PHP, etc.) each 'case' section of a 'select' (called 'switch' in other languages) statement has to include a 'break', otherwise, without a break statement, every statement from the matched case label to the end of the 'select', including the default, is executed.

PHP also extends the 'break' statement by allowing a number to follow the 'break' to indicate how many levels of control structures to break from. This is *very* nice to have.

Matthew
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

mathew180 said:
Greetings,
I'd love to have break and continue added to PB, after the new variable types of course!
Break, continue, double variables and other things have been promised for later versions of PB.

Fred, please can you give us some idea when, so we can make plans.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

I don't have a deadline for now, but probably before the end of the year.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

Fred wrote:I don't have a deadline for now, but probably before the end of the year.
pressure, pressure, pressure :wink:
SPAMINATOR NR.1
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

Fred, thanks for your timescale, seems reasonable to me.

For your information this is my personal prioritised wish list:
1) Doubles
2) Set JPG save quality
3) Mod function
4) Break keyword in loops

Geoff
kwag
User
User
Posts: 35
Joined: Thu Jul 17, 2003 10:03 pm
Contact:

Post by kwag »

geoff wrote:Fred, thanks for your timescale, seems reasonable to me.

For your information this is my personal prioritised wish list:
1) Doubles
2) Set JPG save quality
3) Mod function
4) Break keyword in loops

Geoff
Move that "4)" to the top, and also add "continue", together with "break" ;)
We need exit conditions badly :!:

-Karl
Post Reply