Solved

VB to Delphi-how to use "step"??

Posted on 2002-04-06
4
214 Views
Last Modified: 2010-04-04
Let`s see this code:
------------
for i = 1 to 100 step 2
.....
next i
------------
but in Pascal, there isn`t the keyword "step",so how can i do ?thank you very much.
--
I come from China and i 18 years old,my english is very poor.I want to make friends with you!
E_mail:fanweixiao@sina.com
0
Comment
Question by:VitaminC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 6923448
Hi VitaminC
In Object Pascal there is only two types of for loop:
for i:= 1 to 10 do
and
for i:= 10 to 1 do
so that if you want to step by 2 to 100 you can do this:
for i:= 1 to 50 do
  Writeln((i - 1) * 2 + 1);

Motaz
motaz1@yahoo.com
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6923464
Or something like this

var
  i: Integer;
begin

  i := 1;
  repeat
    DoYourCodeHere;
    Inc(i, 2);
  until i >= 100;

end;
0
 
LVL 10

Accepted Solution

by:
Jacco earned 10 total points
ID: 6923505
Motaz:
for i:= 10 downto 1 do
You forgot downto. I forget it too sometimes. But Delphi will not do anything then :-)

VitaminC:
You could also use a while loop (the third type)

i := 1;
while i <= 100 do
begin
  DoYourStuff;
  Inc(i, 2);
end;

Regards Jacco





0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6924233
:)
if you still want the 'for' loop you could do an unoptimized func like

for I:=0 to 100 do
  if (I mod 2) = 0 then DoYourCode;

while and repeat are preferable for this kinda thing
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question