Exit if

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2835
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Exit if

Post by Michael Vogel »

I'd like to have a "Exit if" line instead of the "If Then Break" thing...

Code: Select all

Repeat
  ;
	If GetAsyncKeyState_(#VK_ESCAPE)
	  Break
	EndIf
	;
ForEver
...it's just a little bit more compact, that's all...

Code: Select all

Repeat
  ;
	Exit If GetAsyncKeyState_(#VK_ESCAPE)
	;
ForEver
[/code]
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Exit if

Post by PB »

In the meantime you can do this:

Code: Select all

Macro ExitIf (code)
  If code : Break : EndIf
EndMacro

Repeat
  ExitIf (GetAsyncKeyState_(#VK_ESCAPE))
ForEver
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Actually because of PureBasic's naming convention it should be:

Break
BreakIf

:)
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

good tip.
so, just to finish the story :

Code: Select all

Macro BreakIf(code, depth)
  If (code) : Break depth : EndIf 
EndMacro 

For i = 0 To 10
  For j = 0 To 10
    BreakIf((i=2) And (j=3), 2) 
  Next
Next

Debug i
Debug j
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Dr. Dri
Enthusiast
Enthusiast
Posts: 243
Joined: Sat Aug 23, 2003 6:45 pm

Post by Dr. Dri »

yo can also add "= 1" after depth to make it optional

Dri ;)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I suggest allowing a dynamic expression for BreakLevel. If the BreakLevel is 0 then it won't break.
Post Reply