Solved

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

Posted on 2002-04-06
4
210 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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