循环和一半控制 [英] loop and a half controlled

查看:100
本文介绍了循环和一半控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们什么时候使用循环半?另外,如果有人简要说明如何编写代码吗?

When do we use loop and a half? Also, should someone briefly elaborate how to write its code?

推荐答案

你使用loop-and-a-half来避免重复代码从循环外部到内部。示例:

You use loop-and-a-half to avoid repeating code from outside the loop to the inside. Example:

read a;
while a != b do
  stuff;
  read a;
end

变为

while true do
  read a
  if a == b then break
  stuff;
end

现在我只在一个地方阅读。

Now I only have the read in one place.

这篇关于循环和一半控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆