By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,566 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

Question about For Next loop. Need help.

P: 2
Hi
Basically I am print out a group of number with a certain increment. However I found out a wierd thing happened from the result
The code I wrote:

Dim number1, number2, counter, increment As Double

Console.Write("Enter number1:")
number1 = Console.ReadLine
Console.Write("Enter number2:")
number2= Console.ReadLine
Console.Write("Enter increment: ")
increment = Console.ReadLine For count = lower_flow_rate To upper_flow_rate Step increment
count = count + increment
Console.WriteLine("{0:F}", count)
next
I was trying to print out a group of number from 0.8-1.5 with the increment of 0.05. However when the result came out it's 0.85,0.95, 1.05, 1.15,1.25, 135.1.45. and the increment is not 0.05 but 0.1.
But when i try any number that is great than 1, it works. Fox example number from 1.0-1.5, all the numbers that are printed out are with the 0.05 increment.
I got really confused here.
can anyone plz help me with this

Really appreciate!!!
Oct 14 '06 #1
Share this Question
Share on Google+
1 Reply


Expert 5K+
P: 8,434
Just a quick one to think about - your DIM statement may not be producing exactly what you expect. Keeping in mind that I don't know what version of BASIC you're working with, in my one (VB6) this statement:
Expand|Select|Wrap|Line Numbers
  1. Dim number1, number2, counter, increment As Double
would create increment as a Double, and the rest as whatever the default type is (probably Variant). Perhaps you could try this, just to see whether it makes any difference:
Expand|Select|Wrap|Line Numbers
  1. Dim number1 As Double, number2 As Double, counter As Double, increment As Double
This is just a general tip - make sure you know what your code is doing, before you decide it shouldn't be doing it. :)

I have no idea whether this will help in your specific case.
Oct 18 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.