Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在终止值C+之前查找序列的最后一个值+;_C++_Loops_Increment - Fatal编程技术网

C++ 在终止值C+之前查找序列的最后一个值+;

C++ 在终止值C+之前查找序列的最后一个值+;,c++,loops,increment,C++,Loops,Increment,在这个循环中,x增加了太多倍 int x = 0; while (x < 10) { x = x + 3; } cout << x; intx=0; 而(x

在这个循环中,x增加了太多倍

int x = 0;
while (x < 10)
{
    x = x + 3;
}
cout << x;
intx=0;
而(x<10)
{
x=x+3;
}
cout例如:

    int last = 0;
    for (int x = 0; x < 10; x+=3)
    {
        last = x;
    }
    cout << last;
int last=0;
对于(int x=0;x<10;x+=3)
{
last=x;
}
cout例如:

    int last = 0;
    for (int x = 0; x < 10; x+=3)
    {
        last = x;
    }
    cout << last;
int last=0;
对于(int x=0;x<10;x+=3)
{
last=x;
}

cout如果要查看最后一个值,最好将其减少与增加相同的量

int x = 0;
while (x + 3 < 10)
{
x = x + 3;
}
x = x -3;
intx=0;
而(x+3<10)
{
x=x+3;
}
x=x-3;

另一种方法是在循环中使用break语句,并使用适当的条件将其保留。

如果要查看最后一个值,最好将其减少与增加值相同的量

int x = 0;
while (x + 3 < 10)
{
x = x + 3;
}
x = x -3;
intx=0;
而(x+3<10)
{
x=x+3;
}
x=x-3;

另一种方法是在循环中使用break语句,并使用适当的条件将其保留。

使用代码,您可以尝试:

int x = 0;
while (x+3 < 10)
{
    x = x + 3;
}
cout << x;
intx=0;
而(x+3<10)
{
x=x+3;
}

cout使用您的代码,您可以尝试:

int x = 0;
while (x+3 < 10)
{
    x = x + 3;
}
cout << x;
intx=0;
而(x+3<10)
{
x=x+3;
}

是否可能在生成下一个值之前保存每个值,然后当/如果下一个值违反约束时,使用存储的值?是否可能在生成下一个值之前保存每个值,然后当/如果下一个值违反约束时,使用存储的值?