0

Is it possible to iterate over an associative array with wildcard "*" using foreach loop?

0

1 Answer 1

3

No. IEEE 1800-2012 § 7.8.1 Wildcard index type states:

Associative arrays that specify a wildcard index type shall not be used in a foreach loop (see 12.7.3) or with an array manipulation method (see 7.12) that returns an index value or array of values.

Sign up to request clarification or add additional context in comments.

1 Comment

The reason for this restriction is that the foreach construct needs to declare a local iterator variable, and that variable needs a type. The wildcard index is left over from the Vera language, which did not have the ability to declare an index type. Do not use wildcard indexes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.