[英]Newbie syntax issue: error: expected ';' before ')' token
在兩個for循環上(即:for(len ...和for(wid ...)),我收到相同的錯誤消息:
錯誤:預期為';' 在')'標記之前
void
init(void)
{
//fills board up with numbers
int tile = (d*d - 1);
int len = 0;
int wid = 0;
for(len < d; len++)
{
for(wid < d; wid++)
{
board[len][wid] = tile;
tile--;
}
}
}
很抱歉提出與以前類似的問題,但是我是一個非常困惑的新手!
每個for循環都需要包含3個部分(初始化,測試,更新),如果您沒有一個或多個部分,則仍然必須提供這兩個部分;
,所以
for(len < d; len++)
^
|
應該真的是
|
v
for(;len < d; len++)
與函數中的其他for循環相同。
例如,這是使用for
設置無限循環for
:
for(;;)
跳過所有部分,但仍然需要兩個分號。
也許這是for循環上的教程/參考 ,作為復習/參考很有用。
通常,for循環包含三個部分:
for (initialization; check; update) { ... }
在您的代碼中,您缺少初始化部分。 您在for循環中缺少分號表示您不需要初始化子句(因為您在上面這樣做了):
void
init(void)
{
//fills board up with numbers
int tile = (d*d - 1);
int len = 0;
int wid = 0;
for(;len < d; len++)
{
for(;wid < d; wid++)
{
board[len][wid] = tile;
tile--;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.