Page 1 of 1
For var in (string1, string, string3)
Posted: Fri Sep 08, 2023 5:43 pm
by elwood
Such feature would be great in PB:
For os in ("Windows", "Linux", "MacOS")
Debug "PB is available for " + $os
Next
Re: For var in (string1, string, string3)
Posted: Fri Sep 08, 2023 5:52 pm
by Caronte3D
Code: Select all
NewMap OS.s()
OS("W") = "Windows"
OS("L") = "Linux"
OS("M") = "MacOS"
ForEach OS()
Debug "PB is available for " + OS()
Next
Re: For var in (string1, string, string3)
Posted: Fri Sep 08, 2023 5:55 pm
by Mijikai
Something:
Code: Select all
DataSection:Data.s "Windows","Linux","MacOs":EndDataSection
For i = 0 To 2
Read.s s.s:Debug s
Next
Re: For var in (string1, string, string3)
Posted: Fri Sep 08, 2023 6:16 pm
by Caronte3D
Code: Select all
OS.s= "Windows,Linux,MacOs"
For i = 1 To CountString(OS, ",")+1
Debug StringField(OS, i, ",")
Next
Re: For var in (string1, string, string3)
Posted: Fri Sep 08, 2023 9:07 pm
by mk-soft
There are many ways to do this.
LinkedList also maintains the order.
"For xyz in list" comes more from vb programming and requires an object list.
Code: Select all
Macro AddElementValue(_List_, _Value_)
AddElement(_List_) : _List_ = _Value_
EndMacro
NewList OS.s()
AddElementValue(OS(), "Windows")
AddElementValue(OS(), "Linux")
AddElementValue(OS(), "MacOS")
ForEach OS()
Debug OS()
Next
Re: For var in (string1, string, string3)
Posted: Mon Sep 11, 2023 12:52 am
by Quin
This would actually be quite nice, but we can't even declare arrays inline, I very highly doubt we're going to get convenience features like this
Seems the PB team doesn't really care about syntax sugar and other things that would make code so much shorter. Not a position I personally agree with, but it's their project.
Re: For var in (string1, string, string3)
Posted: Thu Jan 04, 2024 12:11 am
by elwood
Thanks everyone for the ideas.
I tend to think our suggestions could make a better Purebasic but I just read
this thread so I now understand it will not happen.
I wonder why some people think everything should be free. Our meal is not free, neither our car is, so...
Re: For var in (string1, string, string3)
Posted: Thu Jan 04, 2024 2:48 am
by Demivec
elwood wrote: Thu Jan 04, 2024 12:11 am
I wonder why some people think everything should be free. Our meal is not free, neither our car is, so...
IMHO, your pondering seems a little bit off the mark. There was a purchase and what was purchased is what is being expected and also what is being provided, nothing more and nothing less. To Fred and the PureBasic Team's credit, it is a genuine bargain and a treasure. I am not alone in advocating for showing appreciation, support, encouragement and so forth through generous contributions if one is able to. Others contribute to the value of PureBasic in other ways, including in the forums.
Re: For var in (string1, string, string3)
Posted: Thu Jan 04, 2024 3:50 am
by AZJIO
Quin wrote: Mon Sep 11, 2023 12:52 am
This would actually be quite nice, but we can't even declare arrays inline, I very highly doubt we're going to get convenience features like this
Seems the PB team doesn't really care about syntax sugar and other things that would make code so much shorter. Not a position I personally agree with, but it's their project.
1. Then you get a function by combining two logical operations, then what if you need only one logical operation? You will also waste time doing unnecessary operations (assigning an empty string when it is not required).
2. If you create new functions every time, you will have to support them. Sources will become incompatible due to differences in functions. In this case, you can create a library of new functions created on the basis of PureBasic. For example, you can take functions from different programming languages and make their analogues by writing them in the PureBasic language, so that those people who came from another programming language do not feel the limitations and are immediately provided with greater opportunities.
For example, make a "slice" function from the "js" programming language
Code: Select all
var sString = "Hello";
sString = sString.slice(-4,-2)
WScript.Echo(sString);