爲什麼在這個循環中有2個分號?此代碼正常工作,但我想知道這是如何工作的。任何幫助表示讚賞:)「for(;;){}」裏面2分號的用途是什麼?
public void CurrentDate() {
Thread clock = new Thread() {
public void run() {
for (;;) {
try {
Calendar cal = new GregorianCalendar();
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day = cal.get(Calendar.DAY_OF_MONTH);
date.setText("Date: " + year + "/" + (month + 1) + "/" + day);
int second = cal.get(Calendar.SECOND);
int minute = cal.get(Calendar.MINUTE);
int hour = cal.get(Calendar.HOUR);
time.setText("Time: " + hour + ":" + (minute) + ":" + second);
sleep(1000);
} catch (InterruptedException ex)
{
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
};
clock.start();
}
ist a *** for *** ever loop –
它用於執行for循環而不終止它或者沒有檢查任何condition.But線程將被停止一秒鐘,因爲你已經寫了代碼,第二,循環將開始執行,並停止一秒鐘,這件事情繼續下去,你會得到一個時鐘。 –