PBXB64 Control Flow

Full Control Flow Standard

Complete control flow with FOR loops (7 integer types + float, negative STEP), WHILE, DO/UNTIL, SELECT CASE (nesting, TO ranges, IS expressions), GOSUB/RETURN, EXIT, ON GOTO, ON KEY CALL, and colon statement separators on a single line.

FOR Loops - 7 Integer Types + Float + Negative STEP

FOR with all integer types
FUNCTION PBMAIN() AS LONG LOCAL g AS LONG LOCAL i AS LONG ' Standard LONG FOR i = 1 TO 3 g = g + i NEXT PRINT "LONG sum: "; g ' 6 ' Negative STEP FOR i = 10 TO 1 STEP -1 g = g + 1 NEXT PRINT "Negative: "; g ' 16 ' DWORD LOCAL dw AS DWORD FOR dw = 1 TO 3 g = g + 1 NEXT ' WORD, INTEGER, BYTE, QUAD, CURRENCY all supported FUNCTION = 0 END FUNCTION

FOR loops support LONG, INTEGER, QUAD, DWORD, WORD, BYTE, CURRENCY (all tested individually), and DOUBLE/SINGLE/EXTENDED with float STEP. Negative STEP works correctly for all integer types.

SELECT CASE - Nested, TO Ranges, IS Expressions

SELECT CASE with all forms
FUNCTION PBMAIN() AS LONG LOCAL x AS LONG x = 25 SELECT CASE x CASE 1 TO 10 PRINT "1-10" CASE 11 TO 20 PRINT "11-20" CASE IS > 20 PRINT "Greater than 20" CASE 25 PRINT "Exactly 25" CASE ELSE PRINT "Other" END SELECT FUNCTION = 0 END FUNCTION

SELECT CASE supports: exact match, TO ranges, IS > < = <> expressions, CASE ELSE, and nested CASE blocks. No fall-through to outer CASE ELSE.

ON KEY CALL - Keyboard Hook Subroutines

PBXB64 Addition Registers a low-level keyboard hook (WH_KEYBOARD_LL) that calls a named PB subroutine on key press/release.

ON KEY CALL - keyboard events
DECLARE SUB OnKeyPress() ON KEY DOWN CALL OnKeyPress SUB OnKeyPress() PRINT "Key pressed!" END SUB FUNCTION PBMAIN() AS LONG PRINT "Press any key..." SLEEP 5000 FUNCTION = 0 END FUNCTION

ON KEY [DOWN|UP] CALL SubName registers a WH_KEYBOARD_LL hook. The named subroutine is called when the specified key event occurs. Works in console and GUI modes.

Colon Separator - Multiple Statements per Line

Colon statement separator
FUNCTION PBMAIN() AS LONG LOCAL a AS LONG : LOCAL b AS LONG a = 1 : b = 2 : PRINT a + b IF a = 1 THEN PRINT "One" : PRINT "Still One" FUNCTION = 0 END FUNCTION

The colon : separator allows multiple statements on a single line. Both statements are correctly parsed and executed. Critical for compact code layouts.

Other Control Flow

WHILE, DO, EXIT, GOSUB
FUNCTION PBMAIN() AS LONG LOCAL i AS LONG ' WHILE i = 0 WHILE i < 3 PRINT "WHILE "; i i = i + 1 WEND ' DO/UNTIL i = 0 DO i = i + 1 IF i = 2 THEN EXIT DO LOOP UNTIL i >= 5 PRINT "After EXIT DO: "; i ' 2 ' GOSUB/RETURN GOSUB MySub PRINT "Back from sub" FUNCTION = 0 MySub: PRINT "In subroutine" RETURN END FUNCTION

WHILE/WEND, DO/UNTIL/LOOP, EXIT DO/EXIT FOR/EXIT FUNCTION, GOSUB/RETURN, and ON GOTO all fully implemented with correct codegen and no infinite loops.

Back to feature list