Code: Select all
For i = 1,2,7,8,-5,100
...
Next i
Code: Select all
For i = 1,2,7,8,-5,100
...
Next i
Code: Select all
AddMultipleElements(List(), 1,3,-5,8,10)
ForEach List()
Next
Code: Select all
Macro dq
"
EndMacro
Macro AddElementValues(List, v1, v2=, v3=, v4=, v5=, v6=, v7=, v8=)
LastElement(List)
AddElement(List)
List = v1
CompilerIf Bool(dq#v2#dq <> "") : AddElement(List) : List = v2 : CompilerEndIf
CompilerIf Bool(dq#v3#dq <> "") : AddElement(List) : List = v3 : CompilerEndIf
CompilerIf Bool(dq#v4#dq <> "") : AddElement(List) : List = v4 : CompilerEndIf
CompilerIf Bool(dq#v5#dq <> "") : AddElement(List) : List = v5 : CompilerEndIf
CompilerIf Bool(dq#v6#dq <> "") : AddElement(List) : List = v6 : CompilerEndIf
CompilerIf Bool(dq#v7#dq <> "") : AddElement(List) : List = v7 : CompilerEndIf
CompilerIf Bool(dq#v8#dq <> "") : AddElement(List) : List = v8 : CompilerEndIf
EndMacro
NewList MyList()
AddElementValues(MyList(), 1,3,-5,8,10)
ForEach MyList()
Debug MyList()
Next
Data can be used, too:infratec wrote:why not use a List() and ForEach ?
I see no real reason for the 'other' syntax.
Code: Select all
Repeat
Read n
Debug n
Until n=999
DataSection
Data.l 1,2,7,8,-5,100,999
EndDataSection
Oh nice!Code: Select all
Macro dq " EndMacro Macro AddElementValues(List, v1, v2=, v3=, v4=, v5=, v6=, v7=, v8=) LastElement(List) AddElement(List) List = v1 CompilerIf Bool(dq#v2#dq <> "") : AddElement(List) : List = v2 : CompilerEndIf CompilerIf Bool(dq#v3#dq <> "") : AddElement(List) : List = v3 : CompilerEndIf CompilerIf Bool(dq#v4#dq <> "") : AddElement(List) : List = v4 : CompilerEndIf CompilerIf Bool(dq#v5#dq <> "") : AddElement(List) : List = v5 : CompilerEndIf CompilerIf Bool(dq#v6#dq <> "") : AddElement(List) : List = v6 : CompilerEndIf CompilerIf Bool(dq#v7#dq <> "") : AddElement(List) : List = v7 : CompilerEndIf CompilerIf Bool(dq#v8#dq <> "") : AddElement(List) : List = v8 : CompilerEndIf EndMacro NewList MyList() AddElementValues(MyList(), 1,3,-5,8,10) ForEach MyList() Debug MyList() Next
Code: Select all
For i = -5 To 100
Select i
Case 1,2,7,8,-5,100
Debug i
EndSelect
Next
Code: Select all
-5
1
2
7
8
100
Code: Select all
Case 1 To 5, 7, 8, -5, 100
This is the behaviour of PureBasic macros at least since July 2010, when freak explained it on the German forum.kenmo wrote:Did Macro behavior change sometime? I thought you couldn't do this (I thought CompilerIfs were processed BEFORE Macros were expanded out)
Code: Select all
CompilerIf (#PB_Compiler_OS = #PB_OS_Windows)
Macro SelectGadget(Gadget)
SendMessage_(GadgetID(Gadget), #EM_SETSEL, 0, -1)
SetActiveGadget(Gadget)
EndMacro
CompilerElse
Macro SelectGadget(Gadget)
SetActiveGadget(Gadget)
EndMacro
CompilerEndIf
I was talking only about code (including CompilerIf etc.) inside of a macro definition, as in mk-soft's example.kenmo wrote:Strange... in some ways, CompilerIf must be evaluated before Macros, or else code like this would not compile (multiple-definition macro)
Code: Select all
CompilerIf (#PB_Compiler_OS = #PB_OS_Windows) Macro SelectGadget(Gadget) SendMessage_(GadgetID(Gadget), #EM_SETSEL, 0, -1) SetActiveGadget(Gadget) EndMacro CompilerElse Macro SelectGadget(Gadget) SetActiveGadget(Gadget) EndMacro CompilerEndIf
Code: Select all
Macro SelectGadget(Gadget)
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(GadgetID(Gadget), #EM_SETSEL, 0, -1)
SetActiveGadget(Gadget)
CompilerElse
SetActiveGadget(Gadget)
CompilerEndIf
EndMacro