我想打印,如:使用循環重複無限次的語句?
for(int i=0;i<should be infinite;i++)
{
Data is Loading.
sleep(100);
Data is Loading..
sleep(100);
Data is Loading...
sleep(100);
}
下面
是它不工作
package com.queen.a01_simple_request;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
for (; ;) {
try {
textView.setText("Downloading The File");
Thread.sleep(1000);
textView.setText("Downloading The File.");
Thread.sleep(1000);
textView.setText("Downloading The File..");
Thread.sleep(1000);
textView.setText("Downloading The File...");
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
}
現在,這應該循環無限代碼。點應該永遠改變。我不想設置像我這樣的價值< 1000.我想實現這一點。
如果你想要一個infinit循環然後只是做一個'while(true)' – mayha
你能給我舉個例子嗎? –
簡單地省略guard條件:'for(int i = 0;/* nothing * /; i ++)'。 –