Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to write a loop that counts until infinity, which may consist of a negative or a positive number.

Is this possible, please?

In other languages, I would probably loop till the size of an array with an undefined maximum size, however, how do I deal with the possibility of overflow?
for my $i (0 .. $#array) {
    for my $j (0 .. $#array) {
        next if $j == $i;
        # Compare $i, $j
    }
}

References
1. http://en.wikipedia.org/wiki/Big_O_notation[^]Big O Notation
2. http://www.perlmonks.org/?node_id=573138[^]
Posted
Updated 19-Jun-14 21:46pm
v2
Comments
OriginalGriff 20-Jun-14 3:51am    
What does that have to do with .NET?
Looks like PHP to me...

1 solution

There is no concept of infinity for integer types.
The best you could do is to put it in a while loop:
C#
int counter = 0;
while (true) {
   counter++;
}

But it will overflow at some point.

Infinity is very very long, especially near the end.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900