不能设置!
可以变通一下:
for i:=1 to 20 do
begin
if (i mod 2)=1
then ...
end;
这样步长就为2了
可以变通一下:
for i:=1 to 20 do
begin
if (i mod 2)=1
then ...
end;
这样步长就为2了
解决方案 »
- delphi7 压缩excel出现乱码
- 问题:如何把某条记录向上或向下移动一行?
- locate查询中莫名其妙的错误???
- Delphi有没有静态成员变量的?
- 一个回帖多但还没解决的问题
- 问:大家在写数据库程序时: 是用那些控件来显示数据集的!???我常用TDBGrid控件,但发现(如果dataset 是来自两个表时 ), 操作delete 会将两
- 在线,如何将当前时间的小时、分钟、秒分别取出来赋给三个变量?
- 请问一个TREEVIEW的问题,为什么最后一个节点没有?
- IdUdpServer控件的用法?谁有小程序,给个例子
- Delphi6+SQL2000,三层模式下,如何存储与读取JPG格式的图像字段?
- 用Dephi作cgi,前台提交的method="get"正常,post时就要我下载cgi程序,cgi内容s:=request.QueryFields.Strings[0]
- 有关打印的问题
The syntax of a for statement isfor counter := initialValue to finalValue do statementorfor counter := initialValue downto finalValue do statement
不服气可以去信骂inprise:)
counter is a local variable (declared in the block containing the for statement) of ordinal type, without any qualifiers.
initialValue and finalValue are expressions that are assignment-compatible with counter.
statement is a simple or structured statement that does not change the value of counter.
counter不能改变.
for 循环实际上是while循环的一种特例,对计数器作了优化(用了CPU的寄存器)。
如真想用for循环,可如此:
for counter := 0 to (finalValue - initialValue) div step do statement
在delphi4.0以上根本不能用,编译错误.
for i:=0 to 20 do
begin
j:=i mod 2;
if j<>0 then
break
else
//do your job 实现步长2;
end;
其实,在pascal中,修改for循环变量值是不明智的,因为有些pascal的编译程序在循环开始时已经算出了循环的次数,改了也没用的(好象在Delphi中也是这样)。
如果确实需要步长不为1,在pascal中还有repeat .. until和 while 两个语句来完成用户的需要。不一定要用for。