开发者

How do i go pass an integer's value of 2^62 -1 in a for loop

How may i actually specify a for loop with an iterator value larger than an int's max size?

i.e. i would like to loop 开发者_运维知识库2^62 -1 times.

EDIT: 2^62 -1


for(long i = 0; i < (1L << 62) - 1; ++i){
    //loop
}


That will take you essentially forever on the hardware of today and the foreseeable future.

Try and refine your algorithm to be more efficient.


Just use longs for your loop counters and use long literals in your loop test (e.g. 1000000000000L). If longs are too small for you, you can use BigInteger.

As other answers have stated, you will be waiting for a long long time for your loops to end. tell us how it goes when its done :).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜