如果您学会正确缩进(格式化)您的代码,问题就非常清楚。此答案基于您发布的原始代码,然后添加更多内容并删除一些内容以进行更改。然而,答案中的信息仍然与问题有关。
你贴什么:
Program Arrayexamp(output); Var counter,index,input: Integer; A : Array[1..15] of Integer;
begin
For index := 1 to 15 do
begin read(input);
A[index] := input;
index++
end;
begin
For index := 1 to 15 do
If (counter mod 2 = 0) Then B[counter]=A[counter]*3 Else B[counter]=A[counter]-5; end.
如何它看起来正确格式化:
Program Arrayexamp(output);
Var
counter,index,input: Integer;
A : Array[1..15] of Integer;
begin
For index := 1 to 15 do
begin
read(input);
A[index] := input;
index++
end;
begin
For index := 1 to 15 do
If (counter mod 2 = 0) Then
B[counter] = A[counter] * 3
Else B[counter]=A[counter]-5;
end.
的问题是清楚的:你有没有begin
在下部区段匹配的end;
。实际上,begin
是完全不必要的,可以删除。
第二个问题是for
循环本身会增加循环变量,因此在循环内修改该计数器是非法的。删除index++;
行。 (请参阅下一段。)
第三个问题是Pascal不支持预增或后增操作符,因此index++
是无效的语法。改为使用index := index + 1;
或Inc(index);
。
写了正确的代码:
Program Arrayexamp(output);
Var
counter,index,input: Integer;
A: Array[1..15] of Integer;
begin
For index := 1 to 15 do
begin
read(input);
A[index] := input;
end;
For index := 1 to 15 do
if (counter mod 2 = 0) Then
B[counter] = A[counter] * 3
Else B[counter]=A[counter] - 5;
end.
有关语法和使用的begin..end
帕斯卡的更多信息,请参考这个答案我写了Proper structure syntax for Pascal if then begin end
*存在一些误区*是无用的,除非你告诉我们这些错误究竟是什么。他们在屏幕上,就在你的面前。没有理由不把它们包含在你的文章中,所以我们也有它们。此外,如果您正确格式化代码,问题就非常明确。 –
可能的重复[适当的结构语法为帕斯卡尔如果然后开始结束和; (在Inno Setup中)](http://stackoverflow.com/questions/28221394/proper-structure-syntax-for-pascal-if-then-begin-end-and-in-inno-setup) –
@nil:No , 不是。还有其他问题。阅读我的答案。 (我写了你的建议副本的答案,并将其链接到我的帖子中,这不是重复的。) –