如果您學會正確縮進(格式化)您的代碼,問題就非常清楚。此答案基於您發佈的原始代碼,然後添加更多內容並刪除一些內容以進行更改。然而,答案中的信息仍然與問題有關。
你貼什麼:
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 , 不是。還有其他問題。閱讀我的答案。 (我寫了你的建議副本的答案,並將其鏈接到我的帖子中,這不是重複的。) –