循环复制循环
嗨,我试图执行磁盘调度算法(C-SCAN)。我有一个有效的if语句循环,但是我试图将其更改为ther loop或其他选项以删除断路语句。
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
while ( initial>RQ[i] )
{
index =i;
i++;
}
以上循环是我试图复制的内容,如我的时循环中所示。但是,它的工作方式并不相同。 任何帮助将不胜感激
Hi im trying to do a disk scheduling algorithm (C-SCAN).I have a for loop with an if statement that works, however im trying to change it to a while loop or another option to remove the break statement.
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
while ( initial>RQ[i] )
{
index =i;
i++;
}
The above for loop is what im trying to replicate as seen in my while loop. however it is not working the same way.
any help will be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表格循环的
等同于:
因此,您的循环将被重写为:
A
for
loop of the formis equivalent to:
So your loop would be rewritten as:
删除
break
语句的一种可能性是引入一个附加的标志变量,该变量应在应终止循环时设置。但是,我个人认为使用
break
语句更好。One possibility of removing the
break
statement would be to introduce an additional flag variable which gets set when the loop should be terminated.However, I personally consider it better to use a
break
statement.