question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loop over range should use 'int' variable if endpoints are 'small'

See original GitHub issue

Given:

for (i in 0:10) { ... }
for (i in 1..10) { ... }

Or:

small Integer x = 0;
small Integer y = 10;
for (i in x:y) { ... }
for (i in x..y) { ... }

The compiler should use an int for the loop variable i.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
gavinkingcommented, Nov 4, 2016

That would be fine by me.

1reaction
tombentleycommented, Nov 4, 2016

@xkr47 FTR JVM microbenchmarks have shown that a java for loop over an int is much faster than the same loop using a long. So this would be a worthwhile optimization to have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to iterate through range based for loop with variable end ...
Range -based for loop is pure sugar - it can only iterate over the entire range. If you need to play with the...
Read more >
For loop with range - Learn Python 3 - Snakify
Another use case for a for-loop is to iterate some integer variable in ... Such a sequence of integer can be created using...
Read more >
C Programming Course Notes - Looping Constructs
The correct loop should use an integer counter to complete the loop a given number of times, and use the low end of...
Read more >
Python Range function - How to Use Python Range()
A range is a close interval between two points. This tutorial explains what is Python Range function and how to use it in...
Read more >
Range-based for loop (since C++11) - cppreference.com
Each element of the sequence, in turn, is dereferenced and is used to initialize the variable with the type and name given in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found