Enhanced For-Next loops

Enhanced For-Next loops

At times you may need to execute the same block of statements for different values of a variable, but you can’t use a straight For Next loop because the sequence of values is not regular. For example, you may need to repeatedly call a given procedure passing the first ten prime numbers as arguments:

DoSomething 2DoSomething 3DoSomething 5DoSomething 7DoSomething 11DoSomething 13DoSomething 17DoSomething 19DoSomething 23DoSomething 29

Here is a better approach, based on the Array() function that builds a Variant array on the fly, and a For Next loop that iterates on it:

Dim v As VariantFor Each v In Array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)    DoSomething vNext

You can exploit this trick to build loops that aren’t even based on numeric control variables:

Dim v As VariantFor Each v In Array("Spring", "Summer", "Fall", "Winter")    PrintSaleReport vNext

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several