Actually, this loop would not execute at all

for times = 4 to 10 step -2
next times

So times would be 4 after the loop.

This is a bit of an exception though - you would never write this loop for
any case i can think of.

----- Original Message ----- 
From: "Jodi Silver" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, May 23, 2004 8:22 AM
Subject: Re: [vbhelp] Newbie needing help in loops


> Thank Matt,
> So the final value should always be a step higher than the end value.
> again, if I then had
> for intcnt=4 to 10 step 2
> the final end value would be 12 since it actually ends one step past the
end value.
> So loops to end must all actually end one step past or before the end
value.
> If it was Step -2 then the end value would be 8..correct?
> Jodi
>
> Matt Lorenz Jr <[EMAIL PROTECTED]> wrote:
> The final count ends up 1 higher.
>
> You can prove this to yourself by using the following code:
>
> for times = 1 to 5
>   msgbox times
> next times
> msgbox times '***this shows you times after you have fallen out of the
loop.
>
> yes, for times = 1 to 5 is the same as for times = 1 to 5 step 1
>
> all that means is that the for next loop defaults to step1.  if you want
any
> other step amount you have to use the step statement.
>
> if you want to count backwards you use step -1 or step -5 etc.
>
> for times = 10 to 1 step - 1
>   msgbox times
> next time
> msgbox times
>
> '***Now what do you suppose times is when it falls out of the loop?  zero?
>
> ----- Original Message ----- 
> From: "Jodi Silver" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Sunday, May 23, 2004 5:33 AM
> Subject: Re: [vbhelp] Newbie needing help in loops
>
>
> > I still do not understand what the final value of the IntB would be if
it
> is 1 to 5 and a step 1.
> > Would The final value be 5 or is it one higher (6). That was the
question.
> >
> > 1.Does it end up one or more higher when ending the loop, or is the
final
> count equal to the 5 if the step is 1.
> >
> > 2. Is 1 to 5 the same as 1 to 5 step 1
> >
> > Jodi
> >
> >
> > Matt Lorenz Jr <[EMAIL PROTECTED]> wrote:
> > A for / next loop is just short hand for a do loop.
> >
> > for times = 0 to 10 step 2
> >     msgbox times
> > next times
> >
> > would give you message boxes saying 0, 2, 4, 6...
> >
> > times = 0
> > do until times > 10
> >   msgbox times
> >   times = times + 2
> > loop
> >
> > would give you a message boxes saying 0, 2, 4, 6 ...
> >
> >
> > I think something you are noticing is WHERE in the for next loop the
logic
> > is being checked.
> >
> > With a do loop you can have:
> >
> > do until such and such
> > loop
> >
> > or
> >
> > do
> > loop until such and such
> >
> > I do see your point - your counter always ends up 1 or more higher
> > (depending on your step) after it falls out of the loop.
> >
> > This is okay - you almost never really care what the value is when
falling
> > out of a for / next loop.  This is because you usually have some
> > predetermined number you using.  For example, you know there are 100
times
> > in a list box and you want to process them you would do
> > For Times = 1 to 100
> >   'processing statements
> > Next times
> >
> > More likely you would do this:
> >
> > For times = 0 to lstItems.listcount - 1
> >   'processing statements
> > Next times
> >
> > So you see - you don't care that your times counter gets one past when
you
> > fall out.
> >
> > In general, if you are counting things up to discover the number that is
> > there you use a do loop, not a for next loop.  Example, how many entries
> are
> > in a file on the hard drive called logentries.txt
> >
> > open "c:\logentries.txt" for input as #1
> > ctr = 0
> > do until eof(1) = true
> >     line input #1, linefromfile
> >     ctr = ctr + 1
> > loop
> > close #1
> > msgbox "There are " & ctr & " lines in the file."
> >
> > You can see, you could never properly process a file with unknown
amounts
> of
> > data with a for / next loop.
> >
> > I hope this gives you a little clarity.
> >
> >
> >
> >
> > ----- Original Message ----- 
> > From: "jodidee2004" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Saturday, May 22, 2004 7:50 PM
> > Subject: [vbhelp] Newbie needing help in loops
> >
> >
> > > Hello,
> > > I am a newbie and I need some help understanding some basic concepts.
> > >
> > > If I had a loop structure that read:
> > > For IntNumber=1 to 10
> > > and I also had
> > > For IntNumber 1 to 10 step 1
> > > are these identical loop statements?
> > >
> > > Suppose I had a for next loop like this:
> > > for intB=1 to 7 Step 1
> > > Print IntB
> > > Next IntB
> > >
> > > What would the value of IntB be when the loop stops? I think it would
> > > be 7 is that correct? Or is it 7 plus 1 to get 8.
> > > ---------------------------------------------------------------
> > > I understand that the step counts by those numbers.
> > > So if I had
> > > for IntCount = 4 to 10 step 2
> > > Print IntCount
> > > next Intcount
> > >
> > > the value of the numeric variable would be 12 when the loop stops.
> > >
> > > 4,8,10,12   and it would stop at 12 since this is higher than 10.
> > >
> > > Can someone explain this to me a bit better, I am confused by all
> > > this. Does it increase at the end the amount of steps past the end
> > > value?
> > >
> > > Jodi
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > '// =======================================================
> > >     Rules : http://ReliableAnswers.com/List/Rules.asp
> > >     Home  : http://groups.yahoo.com/group/vbHelp/
> > >     =======================================================
> > >     Post  : [EMAIL PROTECTED]
> > >     Join  : [EMAIL PROTECTED]
> > >     Leave : [EMAIL PROTECTED]
> > > '// =======================================================
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> > '// =======================================================
> >     Rules : http://ReliableAnswers.com/List/Rules.asp
> >     Home  : http://groups.yahoo.com/group/vbHelp/
> >     =======================================================
> >     Post  : [EMAIL PROTECTED]
> >     Join  : [EMAIL PROTECTED]
> >     Leave : [EMAIL PROTECTED]
> > '// =======================================================
> >
> >
> >
> > Yahoo! Groups SponsorADVERTISEMENT
> >
> >
> > ---------------------------------
> > Yahoo! Groups Links
> >
> >    To visit your group on the web, go to:
> > http://groups.yahoo.com/group/vbhelp/
> >
> >    To unsubscribe from this group, send an email to:
> > [EMAIL PROTECTED]
> >
> >    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
> >
> >
> >
> > ---------------------------------
> > Do you Yahoo!?
> > Yahoo! Domains - Claim yours for only $14.70/year
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> >
> >
> >
> > '// =======================================================
> >     Rules : http://ReliableAnswers.com/List/Rules.asp
> >     Home  : http://groups.yahoo.com/group/vbHelp/
> >     =======================================================
> >     Post  : [EMAIL PROTECTED]
> >     Join  : [EMAIL PROTECTED]
> >     Leave : [EMAIL PROTECTED]
> > '// =======================================================
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
> >
>
>
>
>
>
> '// =======================================================
>     Rules : http://ReliableAnswers.com/List/Rules.asp
>     Home  : http://groups.yahoo.com/group/vbHelp/
>     =======================================================
>     Post  : [EMAIL PROTECTED]
>     Join  : [EMAIL PROTECTED]
>     Leave : [EMAIL PROTECTED]
> '// =======================================================
>
>
>
> Yahoo! Groups SponsorADVERTISEMENT
>
>
> ---------------------------------
> Yahoo! Groups Links
>
>    To visit your group on the web, go to:
> http://groups.yahoo.com/group/vbhelp/
>
>    To unsubscribe from this group, send an email to:
> [EMAIL PROTECTED]
>
>    Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Domains - Claim yours for only $14.70/year
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
>
> '// =======================================================
>     Rules : http://ReliableAnswers.com/List/Rules.asp
>     Home  : http://groups.yahoo.com/group/vbHelp/
>     =======================================================
>     Post  : [EMAIL PROTECTED]
>     Join  : [EMAIL PROTECTED]
>     Leave : [EMAIL PROTECTED]
> '// =======================================================
>
> Yahoo! Groups Links
>
>
>
>
>




------------------------ Yahoo! Groups Sponsor ---------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/k7folB/TM
---------------------------------------------------------------------~->


'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [EMAIL PROTECTED]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 

Reply via email to