相关疑难解决方法(0)

有没有办法在C中只创建一个只有两个表达式的for循环?

我在C标准文本中遇到过这个问题,我可以在§6.8.5找到C99或C11的任何版本:

iteration-statement:
  while ( expression ) statement
  do statement while ( expression ) ;
  for ( expression ; expression ; expression ) statement
  for ( declaration expression ;  expression ) statement
Run Code Online (Sandbox Code Playgroud)

这里的第四项似乎for只有一个分号,我在其他地方看不到任何对这种语法的引用.谁能在这里解释我错过了什么?

c for-loop

15
推荐指数
1
解决办法
856
查看次数

为什么不允许第二种语法?

for ( declaration expressionopt ; expressionopt ) statement
Run Code Online (Sandbox Code Playgroud)

for循环的第二种语法只有一个分号,但每当我尝试使用它时,它会产生一个错误,说:

error: expected `;` before `)` token
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
56
查看次数

这种for循环有什么理由吗?

有没有理由在c中写这样的for-loop?(第一个语句留空,高度设置在外面而且......高度变量在其他地方之后也没用过)

lastheight = halfheight;
.
. // some more code changing height, includes setting 
. // lastheight
. // to something that is essentially the height of a wall
.
height = halfheight;
for ( ; lastheight < height ; lastheight++)
Run Code Online (Sandbox Code Playgroud)

它是从Wolfenstein3D源代码中引用的.

c syntax for-loop

-2
推荐指数
1
解决办法
102
查看次数

标签 统计

c ×3

for-loop ×2

syntax ×1