Reputation: 3
While grammar is infinitely repeat when if condition not meeted.
What I want is delay that between start of while grammar and finish of while grammar.
example,
want code.java
int count = 1, sum = 0;
while (count < 11){
count ++;
System.out.println(count);
//(after 30 seconds...) what i want is this code.
}
therefore, i want same output with down code.
1
(after 30 seconds delay..)
2
(after 30 seconds delay..)
...
10
(after 30 seconds delay..)
Please answer. how to delay time between running while grammar?
Upvotes: 0
Views: 106
Reputation: 521279
If you just want your program to pause for 30 seconds at the end of each iteration of the loop then you can use Thread#sleep
for that:
int count = 1, sum = 0;
while (count < 11) {
count ++;
System.out.println(count);
Thread.sleep(30000); // 30 seconds = 30K milliseconds
}
Upvotes: 1