问题
I've following simple while loop code in groovy -
def count = 1
while(count <= 5) {
println "$count"
sleep(5000)
println "Sleeping for 5 seconds"
count++
}
Which indicates that loop is executed only twice still second time Sleeping for 5 seconds
is not run. Actually with this code, while block is expected to be executed 5 times. Can someone help to understand why such a weird behaviour?
When this code is run, output is following -
1
Sleeping for 5 seconds
2
回答1:
This works fine:
~ $ cat doit.groovy
def count = 1
while(count <= 5) {
println "$count"
sleep(5000)
println "Sleeping for 5 seconds"
count++
}
~ $ groovy doit
1
Sleeping for 5 seconds
2
Sleeping for 5 seconds
3
Sleeping for 5 seconds
4
Sleeping for 5 seconds
5
Sleeping for 5 seconds
来源:https://stackoverflow.com/questions/58395746/groovy-while-loop-not-executed-correctly