Community Project: BlitzMax Examples in Helpfiles

BlitzMax Forums/BlitzMax Programming/Community Project: BlitzMax Examples in Helpfiles

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Ok, not really a command reference, but nonetheless handy to include for beginners.
'
' six ways to iterate
'


' using For-Next
For Local t:Int=0 To 15
	Print t
Next

' using For-Step-Next 
For t=0 To 15 Step 1
	Print t
Next

' using For-Until-Next
For Local t:Int=0 Until 16
	Print t
Next

' using Repeat-Until
t=0
Repeat
	Print t
	t:+1
Until t=16


' using Repeat-Exit-Forever
t=0
Repeat
	Print t
	t:+1
	If t=16 Exit
Forever


' using While-Wend
t=0
While t<16
	Print t
	t:+1
Wend

'
' How *not* to iterate using a non-const step:
'

' using For-Step-Next 
Local a:Int=2

'For t=0 To 15 Step a ' <- will cause an error
'	Print t
'Next


'
' How to iterate using a non-const step:
'


' using Repeat-Until
a=2
t=0
Repeat
	Print t
	t:+a
Until t=16


' using Repeat-Exit-Forever
t=0
Repeat
	Print t
	t:+a
	If t=16 Exit
Forever


' using While-Wend
t=0
While t<16
	Print t
	t:+a
Wend


'
' How *not* to iterate downwards using For-Next-Step:
'

Print "------------------"

For Local b:Byte=15 To 0 Step -1
	Print t
Next

For Local c:Short=15 To 0 Step -1
	Print t
Next

' reason: these variables must be signed, which 'byte' and 'short' aren't.
End