Loop through a decimal sequence
NickName:Zach Ask DateTime:2011-10-04T03:45:12

Loop through a decimal sequence

I am writing a loop in VBA for excel, and I would like to loop through a sequence of decimal numbers, rather than integers.

For example:

For i = 1 To 10
    'Do something
Next i

But rather than incrementibg by 1, I would like to increment by 0.5 (or perhaps 5, or really any number other than 1).

Copyright Notice:Content Author:「Zach」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7639881/loop-through-a-decimal-sequence

Answers
GSerg 2011-10-03T19:48:28

Dim i as Single\n\nFor i = 1 To 10 Step 0.5\n '\nNext\n\n\nBut note you can get some unwanted numbers because of the floating numbers not being precise.",


Dr. belisarius 2011-10-03T19:50:19

Sub a()\n For i = 1 To 10 Step 0.1\n Debug.Print i\n Next i\nEnd Sub\n",


More about “Loop through a decimal sequence” related questions

Loop through a decimal sequence

I am writing a loop in VBA for excel, and I would like to loop through a sequence of decimal numbers, rather than integers. For example: For i = 1 To 10 'Do something Next i But rather than

Show Detail

Does for ... in loop loop through a copy of a sequence?

I came across such statements as the following in Matt Neuburg's iOS 13 Programming Fundamentals with Swift: When you cycle through a sequence with for...in, what you’re actually cycling through i...

Show Detail

How can I loop through two tasks in a role using with_sequence?

Problem I need to loop through two separate tasks with_sequence as the {{ item }} value is the name of my stack. For each integer in with_sequence, it needs to loop {{ item }} through task1 once, ...

Show Detail

How to loop through selected items in yaml sequence using haml

I have a yaml sequence containing testimonials that I would like to loop through in full in some places but only partially in others. Briefly, how does one select and loop through specific items in a

Show Detail

SQL Cursor to loop through a column and determine if the range of a sequence

I'm attempting to setup a cursor to loop through a column in my table and determine if the sequence has ended. If the sequence has ended, i want to output the start and end values. For example:

Show Detail

For loop in scala without sequence?

So, while working my way through "Scala for the Impatient" I found myself wondering: Can you use a Scala for loop without a sequence? For example, there is an exercise in the book that asks you to

Show Detail

Specman - Assign uint decimal number to sequence

I have the following sequence: extend CONFIG_ADC_CLK ocp_master_sequence_q { divide_by : uint(bits:4); align_by : uint(bits:4); body()@driver.clock is { var div : uint(bits:...

Show Detail

How to loop through a range of decimal numbers in bash?

I'd like to generate a sequence of equally spaced decimal numbers. For example, I want to echo all numbers between 3.0 and 4.5, with step 0.1. I tried $ for i {3.0..4.5..0.1}; do echo $i; done, bu...

Show Detail

Determine Difference Of Decimal Sequence Dynamically

I need to determine the difference of a given sequence of decimal numbers dynamically. Given the sequence: my_seq <- seq(0, 10, 0.1) Where 0.1 can be any decimal (0.01, 0.5), but am using 0.1 ...

Show Detail

How to efficiently loop through a MongoDB collection in order update a sequence column?

I am new to MongoDB/Mongoose and have a challenge I'm trying to solve in order to avoid a performance rabbit hole! I have a MongoDB collection containing a numeric column called 'sequence' and after

Show Detail