Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Loop with uneven steps?


Reply
 
Thread Tools Display Modes
  #1  
Old 03-01-2005, 11:27 PM
ko99 ko99 is offline
Newcomer
 
Join Date: Feb 2005
Posts: 4
Default Loop with uneven steps?


Is it possible to write a loop where the increments are not uniform? I'd like to gradually increase the size of the step.
Reply With Quote
  #2  
Old 03-01-2005, 11:46 PM
tblpidar tblpidar is offline
Centurion
 
Join Date: Jan 2005
Posts: 157
Default

Well One suggestion would be to create 2 counters for ex:

x = 500 ' whatever the ammount of steps u want
i = 0
j = 0

do until i = x
''' your code is excuted here
i = i + 1
j = j + i '' example value j grows much faster then i
'' whatever other algporithm u want to implement could be multiplied by j or whatever u need to do
i = j ' if you want your loop to skip some steps
loop



It is just a thought, but you can base something on this algorithm, also you can manipulate teh values of i and j or any ammount of variables as the loop is iterating

all you really have to do is come up with an algorithm for how man y steps to skip

hope this helps, or atleast gives u an idea in the right direction
Reply With Quote
  #3  
Old 03-02-2005, 05:09 AM
Illusionist's Avatar
Illusionist Illusionist is offline
Senior Contributor
 
Join Date: Oct 2003
Location: Chattanooga, TN USA
Posts: 1,069
Default

Code:
For i = 0 to 100 Step 3 Debug.print i next i
Reply With Quote
  #4  
Old 03-02-2005, 06:29 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Illusionist: ko99 is trying to make the step uneven and uniform.
Step 3 looks like it's a uniform step.

ko99: You definitely shouldn't use a For Loop for this - having a Do Loop as tblpidar mentioned should work. We don't know exactly what you are using it for, though.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 03-02-2005, 01:39 PM
ko99 ko99 is offline
Newcomer
 
Join Date: Feb 2005
Posts: 4
Default

Thankyou all. I think tblpidar's approach will work.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->