Vector 使用while语句产生无限循环错误
我想知道为什么这是一个无限循环 脚本如下:Vector 使用while语句产生无限循环错误,vector,matlab-guide,Vector,Matlab Guide,我想知道为什么这是一个无限循环 脚本如下: x=1; while x<5; x=2; x=x+2; if x==4; x=x-1; end end x=1; 当x通过此步骤了解为什么x总是小于5时: x=1; while x<5; x=2; // You set x to 2 at the beginning of every single iteration x=x+2; // At this po
x=1;
while x<5;
x=2;
x=x+2;
if x==4;
x=x-1;
end
end
x=1;
当x通过此步骤了解为什么x总是小于5时:
x=1;
while x<5;
x=2; // You set x to 2 at the beginning of every single iteration
x=x+2; // At this point, x == 4
if x==4; // The "if" is unnecessary - of COURSE x == 4 - how could it possibly be anything else?
x=x-1; // x now contains 3
end
end
x=1;
为什么它被标记为C++?为什么它甚至在这里?用铅笔和纸,自己画出来!我对语法有点不熟悉,但看起来他们在每次迭代中将x设置为2,如果x达到4,则减去1,因此显然x不可能达到5。事实上,如果我读对了,那么在每次迭代结束时,x应该包含3(如果我错了,请纠正我)。因为你总是在while循环中定义x=2,所以在循环结束时,x总是3。你能澄清一下你在一开始试图完成什么,这样我们就可以提出一个替代方案吗?