结构问题"for"

problems with the structure "for"

本文关键字:for 问题 结构      更新时间:2023-10-16
#include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std; 
int main()
{
    int i,a=4, b=3;
    for (i=0, i<3, i++)
    {
        if (b%2==0)
        {
            printf("%d+%d=%d", a, b, a+b);
            i++;
        }
        b++
    }
    system("pause");
    return 0;
}

我需要帮助!每次我放它时,它都用 for 来表示:

8 个预期的';'在')'标记之前"

我不知道该怎么办,请帮忙!!

你应该

在循环声明中使用;而不是,

像这样:

for (i=0; i<3; i++) {
} 

这是因为for的三个部分用分号而不是逗号分隔:

for (i=0 ; i<3 ; i++)
//       ^     ^

在 C/C++ 中,使用 ; 分隔 for (...) 语句中的循环条件。

请改用这个:

for (i = 0; i < 3; i++) {
  ...
}
您使用了

逗号而不是分号

for(int i = 0; i != 3; ++i)
{
    //code here
}