EASY EASY EASY question 
Author Message
 EASY EASY EASY question

I cannot for the life of me figure out how to continue a For...Next loop

I'd like to do the following

For i = 1 to 10

..blah blah

        if  x = 5 then continue

..stuff junk

Next i

Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit, stop
or any other keyword I've ever seen.  Please help me!  How do I do this?

----------------
Steve Silberberg

Visit the Air Sickness Bag Museum at:
http://www.*-*-*.com/ ~stevebo/airsick.html
FACT:  Buff Babes Dig Cut Dudes!



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question

Quote:

>I cannot for the life of me figure out how to continue a For...Next loop

>I'd like to do the following

>For i = 1 to 10

>..blah blah

>        if  x = 5 then continue

>..stuff junk

>Next i

>Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit, stop
>or any other keyword I've ever seen.  Please help me!  How do I do this?

>----------------

Try this approach...

i = 1

 Do While i < 10

...blah blah

if x = 5 then exit loop

i = i + 1

...stuff junk

 Loop



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
Steve,
  One easy thing you could do would be to call a sub that does your "do
something" stuff. That way once the do something has completed it returns
you to your loop.
Good Luck!!
   Dave
http://www.erols.com/dparsons

Quote:

>I cannot for the life of me figure out how to continue a For...Next loop

>I'd like to do the following

>For i = 1 to 10

>..blah blah

>        if  x = 5 then continue

>..stuff junk

>Next i

>Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit,
stop
>or any other keyword I've ever seen.  Please help me!  How do I do this?

>----------------
>Steve Silberberg

>Visit the Air Sickness Bag Museum at:
>http://rampages.onramp.net/~stevebo/airsick.html
>FACT:  Buff Babes Dig Cut Dudes!



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
There is no Contuniue in VB. Restructure your code like this:

For i = 1 to 10
    ..blah blah
    If  x <> 5 Then
        ..stuff junk
    End If
Next i

OR Something like this:

For i = 1 To 10
    '..blah blah

    If x = 5 Then GoTo Continue

    '..stuff junk

Continue:
Next i


Quote:
>I cannot for the life of me figure out how to continue a For...Next loop

>I'd like to do the following

>For i = 1 to 10

>..blah blah

>        if  x = 5 then continue

>..stuff junk

>Next i

>Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit,
stop
>or any other keyword I've ever seen.  Please help me!  How do I do this?

>----------------
>Steve Silberberg

>Visit the Air Sickness Bag Museum at:
>http://rampages.onramp.net/~stevebo/airsick.html
>FACT:  Buff Babes Dig Cut Dudes!



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
"Exit Loop" in a Do While loop will end the loop completely.  The C language
keyword "Continue"  just skips the current iteration and continues with the
next one.  So "Exit Loop" cant be used here.

By the way there it should have been "Exit Do" and not "Exit Loop"


Quote:

>>I cannot for the life of me figure out how to continue a For...Next loop

>>I'd like to do the following

>>For i = 1 to 10

>>..blah blah

>>        if  x = 5 then continue

>>..stuff junk

>>Next i

>>Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit,
stop
>>or any other keyword I've ever seen.  Please help me!  How do I do this?

>>----------------
>Try this approach...

>i = 1

> Do While i < 10

>...blah blah

>if x = 5 then exit loop

>i = i + 1

>...stuff junk

> Loop



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question

Quote:

>I cannot for the life of me figure out how to continue a For...Next loop

VB doesn't have a C style continue command. It does have an Exit For command
which can be used to leave a For loop early. Here are some examples that
describe potential methods you can use .....

Exit For Example.....

    For nLoop = 1 to 10
        'do something
        If nSomething = nLoop Then Exit For
    Next
    'execution continues here when Loop ends or Exit For occurs

Exception with block If.End If example...

    For nLoop = 1 to 10
        'do something
        If nSomething = nLoop Then
           'do something else only if condition is met
        End If
    Next

Exception with GoTo to continue example....

    For nLoop = 1 to 10
Continue_nLoop:
        'do something
        if nSomething = nLoop Then GoTo Continue_nLoop
        'do a lot of complex stuff
    Next

Exception with call to another function example....

    For nLoop = 1 to 10
        'do something
        If nSomething = nLoop Then
           nSomething = ProcessFunction(nSomething, nLoop)
        End If
    Next

Frank Carr



Sun, 24 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
High!

Quote:

> I cannot for the life of me figure out how to continue a For...Next loop

> I'd like to do the following

> For i = 1 to 10

> ...blah blah

>         if  x = 5 then continue

> ...stuff junk

> Next i

> Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit, stop
> or any other keyword I've ever seen.  Please help me!  How do I do this?
> ...

 How could it do anything? It's not VBA-Code, I think...;-)
Put "Option Explicit" in your modul, and you'll see....

I think there have been some good ideas mentioned here, but the nearest
suggestion
to your example is:

For i = 1 to 10
...blah blah
        if  x = 5 then continueStep
...stuff junk
continueStep:
Next i

Ciao,
H.
--
Holger Jannsen - phoenix EDV-Systemtechnik GmbH - Fraunhoferstr.3 - D-25524
Itzehoe




Fri, 29 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
You could try:

For i = 1 To 10
    '... blah blah
    If x <> 5 Then
        '... stuff junk
    End If
Next i

This will skip the "... stuff junk" bit if x = 5 (thus simulating C's
continue).

HTH,

Geoff Lane
Cornwall, UK

Quote:

>I cannot for the life of me figure out how to continue a For...Next loop

>I'd like to do the following
>For i = 1 to 10
>..blah blah
>        if  x = 5 then continue
>..stuff junk
>Next i



Fri, 29 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
Can't you just use an extra NEXT in there like this? :

For i = 1 to 10

..blah blah

        if  x = 5 then Next i

..stuff junk

Next i

I haven't tried this, just a thought.

Dan.



Fri, 29 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question

Quote:
>Can't you just use an extra NEXT in there like this? :

>For i = 1 to 10

>...blah blah

>        if  x = 5 then Next i

>...stuff junk

>Next i

I tried that, and it didn't compile properly.

Given some of the incredibly esoteric functionality available in VB, I can't
imagine why Microsoft left out a staple of programming used in fortran '66.

What were they thinking in those design meeting?

Designer:  Hey, shouldn't we give people a way to increment and continue their
loops from any point within the loop?

Manager:  Naah, who'd ever want to do that?  Besides, it looks too close to
languages we're trying to eradicate with our marketing muscle!

Designer:  But....

Manager:  OK everybody, now let's go over supporting the Hijri Calendar.

----------------
Steve Silberberg

Visit the Air Sickness Bag Museum at:
http://rampages.onramp.net/~stevebo/airsick.html
FACT:  Buff Babes Dig Cut Dudes!



Fri, 29 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question

Quote:

> I tried that, and it didn't compile properly.

> Given some of the incredibly esoteric functionality available in VB, I can't
> imagine why Microsoft left out a staple of programming used in Fortran '66.

> What were they thinking in those design meeting?

I think they tried to make the language robust, yet easy to use.
Whatever you wanted to do, using continue, can be done given
the proper syntax.  Had I known exactly what "Continue" was to
accomplish I might have supplied some code.  Explain it to me
and I'll show HOW that VB can do it.  :)

LFS



Fri, 29 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
Daniel,
  I haven't seen the original message, but I assume you want to
increment  the variable "i" if x=5. If I recall correctly, your code as
written would work in QBasic, but VB doesn't seem to like it.  Modify
the code as follows to jump over "stuff junk" and directly to Next i:

For i = 1 to 10

 ..blah blah

         if  x = 5 then GoTo Skip

 ..stuff junk

 Skip:
 Next i

Quote:

> Can't you just use an extra NEXT in there like this? :

> For i = 1 to 10

> ..blah blah

>         if  x = 5 then Next i

> ..stuff junk

> Next i

> I haven't tried this, just a thought.

> Dan.



Sat, 30 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question
Did you consider this?

For i = 1 to 10
..blah blah
        If x <> 5 Then  'continue
            ..stuff junk
            ..stuff junk
        End If

Quote:
>Next i

Or this?

For i = 1 to 10
..blah blah
        If  x = 5 Then  'continue
            'nothing
        Else
            ..stuff junk
            ..stuff junk
        End If

Quote:
>Next i

Or did you want a graceful exit?

For i = 1 to 10
..blah blah
        If  x= 5 Then Exir For 'continue
 ..stuff junk
Next i

Garry Welsh - Valuad

Quote:

>I cannot for the life of me figure out how to continue a For...Next loop

>I'd like to do the following
>For i = 1 to 10
>..blah blah
>        if  x = 5 then continue
>..stuff junk
>Next i
>Unfortunately, Continue doesn't work.  Nor does break, abort, end, exit,
stop
>or any other keyword I've ever seen.  Please help me!  How do I do this?

>----------------
>Steve Silberberg

>Visit the Air Sickness Bag Museum at:
>http://rampages.onramp.net/~stevebo/airsick.html
>FACT:  Buff Babes Dig Cut Dudes!



Sat, 30 Dec 2000 03:00:00 GMT  
 EASY EASY EASY question

Quote:

>I think they tried to make the language robust, yet easy to use.
>Whatever you wanted to do, using continue, can be done given
>the proper syntax.  Had I known exactly what "Continue" was to
>accomplish I might have supplied some code.  Explain it to me
>and I'll show HOW that VB can do it.  :)

OK, here's the deal.  I want a loop that skips some of the code if any of the
following are true:

        X = 4
        Y = 7
        Z = 10
        W = 1
        R = 4
        T = 3

For i = 1 to 10
        Do stuff....
        if X <> 4 then
                Do stuff, maybe to Y
                if Y <> 7 then
                        Do more stuff, maybe change Z
                        if Z <> 10 then
                                Do more stuff, maybe change W
                                if W <> 1 then
                                        More stuff
                                        if R <> 4 then
                                                More Stuff
                                                if T <> 3 then
                                                        More stuff***
                                                end if
                                        end if
                                end if
                        end if
                Maybe do some stuff to Y
                endif
        Maybe some more stuff to X
        endif    ' I wonder if I have enough endifs???
next i

Now that's the "proper syntax".  Wouldn't this be easier and more readable?

For i = 1 to 10
        Do stuff
        If X = 4 then
                Do some stuff to X
                Continue
        endif

        do stuff, maybe to Y

        if Y = 7 then
                Do some stuff to Y
                Continue
        endif

        Do stuff to Z
        if Z = 10 then Continue
        Do stuff to W
        if W = 1 then Continue
        More Stuff
        if R = 4 then Continue
        More Stuff
        if T = 3 then Continue
        More Stuff***
next i

This way you never get lost trying to match up if/endif plus you don't get
statements that wrap when you're indented 10 levels, such as where the
asterisks are above.  

----------------
Steve Silberberg

Visit the Air Sickness Bag Museum at:
http://rampages.onramp.net/~stevebo/airsick.html
FACT:  Buff Babes Dig Cut Dudes!



Sat, 30 Dec 2000 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. help easy easy question

2. easy filecopy question...but maybe not so easy

3. easy question

4. Easy Loops question?

5. bitmaps, easy question

6. Public functions, easy question

7. Easy question

8. I'm sure that this is an easy question

9. easy question

10. help new to VBA, easy question

11. quick and easy question....please help!

12. How does A2K handle ASP - Many Easy Questions

 

 
Powered by phpBB® Forum Software