Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

integer do variable ending value ?

integer do variable ending value ?

integer do variable ending value ?

In an integer do loop such as

do i=lower,iupper
.... ; enddo

More specifically with an integer do loop variable default step 1 whose upper limit is atleast as great as the lowerwill it always be the case that after the loop normally exits, eg assuming nothing in the loop such that one may jump out of the loop etc., that the do loop variable will always be left 1 higher than the upper limit? So no matter how many statements intervene after the loop as long as the value of the do loop variable is not changed and assuming within the same program unit (within scope) is it guaranteed that this will always be the case ? For example in the above example i will be iupper+1 assuming iupper>=lower,
that i will equal iupper+1 ? Trials I have done always give this result.

RE: integer do variable ending value ?

For many implementations

do i = lower, upper, inc

i will be upper + inc but this is not guaranteed, especially if there is an exit do in the middle of the loop. You also need to check what happens when upper is the maximum integer. maximum integer + inc is undefined or may even wrap round, in which case you will end up with an endless loop.

Don't rely on this if you are using different compilers or working in multiple language because in some languages (like C++, java, C#, Algol68) the value is undefined outside the loop.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close