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 long
s for your loop counters and use long
literals in your loop test (e.g. 1000000000000L
). If long
s 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 :).
精彩评论