If I have code like this
for (long i = 0; i < Long.MAX_VALUE; i++)
{
//do something trivial
}
How long will it take theoretically for the loop to finish?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Suppose, just for argument’s sake, that you’ve got a very fast computer that can perform about 2 billion loop iterations per second (a 2 GHz machine could just barely do that if there really isn’t anything in the loop). Since
Long.MAX_VALUEis 2 billion times 4 billion, that loop will take around 4 billion seconds, or something over 120 years.There’s no point in starting that loop today. Wait until computers get faster, and then it will be done sooner.