How do I iterate over a dictionary?

  • Updated

In Cadence, the language used in the Flow blockchain, you can iterate over a dictionary using a loop. In general, you would use a loop to iterate over each key-value pair in the dictionary.

Here's a general example:

var dictionary: {String: String} = {"Key1": "Value1", "Key2": "Value2", "Key3": "Value3"}

for key in dictionary.keys {
log(key) // prints the key
log(dictionary[key]) // prints the value associated with the key

*Please note that this is a general example and may need adjustments based on your specific use case.

For more detailed information on working with dictionaries in Cadence, you can refer to our Cadence documentation and tutorials.