+ 2

How can we slow down a loop in java ?

While doing some java coding in Android studio, i have stuck to a problem. I have to slow down a while loop i.e. there must be a atleast 1sec gap between each loop perform. Please help ... how can i do this..

28th Feb 2018, 9:46 AM
Bhaskar Jyoti Das
Bhaskar Jyoti Das - avatar
2 Réponses
+ 7
Are you looking for something like this ? while (/*condition*/) { /*do stuff*/ Thread.sleep(timeInMills); }
28th Feb 2018, 10:11 AM
Chrizzhigh
Chrizzhigh - avatar
+ 2
Using some sort of timer would be an alternative. It might be a little bit more work but in my oppinion sleep functions are cheesy x)
28th Feb 2018, 11:13 AM
Kai Schlegel
Kai Schlegel - avatar