对于Java中没有参数的循环 [英] For loop with no parameters in Java

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

问题描述

我正在查看其他人的代码,我找到了这段代码:

I am looking at somebody else's code and I found this piece of code:

for (;;) {

我不是Java专家;这行代码是做什么的?

I'm not a Java expert; what is this line of code doing?

起初,我认为它会创建一个无限循环,但在SAME类中,这个程序员使用

At first, I thought it would be creating an infinite loop, but in the very SAME class this programmer uses

while(true)

哪个(纠正我,如果我错了)是一个无限循环。这两个相同吗?为什么有人会改变他们重复相同过程的方法?

Which (correct me if I'm wrong) IS an infinite loop. Are these two identical? Why would somebody change their method to repeat the same process?

任何见解都会有所帮助,

Any insight would help,

谢谢!

推荐答案

请记住for()的三个子句是[1]初始化[2]终止和[3]递增。由于terminate子句为空,因此循环永远不会终止。这直接取自C语法。

Remember the three clauses of the for() are [1] initialization [2] termination and [3] increment. Since the termination clause is empty the loop never terminates. This is directly taken from C syntax.

这篇关于对于Java中没有参数的循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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