WeiDU and "breaking" out of arrays
Bubb
Member Posts: 1,005
Hello again! I am fairly new to WeiDU, though I have some hobbyist coding background that helps me grasp most things in the documentation. I am struggling with one concept, however, and that is WeiDU's flavor of array.
I'm sure I'm probably reinventing the wheel here, though I'm just trying to get a grasp on the fundamentals. I've written this function here:
Does anyone know how I'd implement a conventional code-break at the marked line? I've thought of using a FOR loop and then shorting the increment variable, or perhaps a WHILE loop also using a "break" variable, though I cannot figure out how to get the size of an array - and thus I cannot set up either of these other cases. Any help would be greatly appreciated!
I'm sure I'm probably reinventing the wheel here, though I'm just trying to get a grasp on the fundamentals. I've written this function here:
/**
* Patch function. Checks if a key is inside of an array.
* INT_VAR key The key to check for.
* STR_VAR array_name The name of the array to check.
* RET result 1 if array contains key, 0 if array doesn't contain key.
*/
DEFINE_PATCH_FUNCTION ARRAY_CONTAINS_KEY
INT_VAR
key = 0
STR_VAR
array_name = ~~
RET
result
BEGIN
result = 0
PHP_EACH ~%array_name%~ AS array_key => array_value BEGIN
PATCH_IF (array_key == key) BEGIN
result = 1
??? <-- I want to break out of the PHP_EACH here
END
END
END
Does anyone know how I'd implement a conventional code-break at the marked line? I've thought of using a FOR loop and then shorting the increment variable, or perhaps a WHILE loop also using a "break" variable, though I cannot figure out how to get the size of an array - and thus I cannot set up either of these other cases. Any help would be greatly appreciated!
0
Comments
If you need to retrieve value associated with the given key, you can do this: