#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Next Loop

If I am in a while or for loop and I have a statement like this:

if 1=1 then
'Go to next iteration of for loop or change cells and go back to top of
while loop
end if


What is the syntax for continuing the loop at this point. Right now, I
create spaghetti code by saying to goto a label like

Goto NextLoop

and then at the bottom of the loop right before the next or loop line, I
have a line:
NextLoop:

But I want to avoid all this goto jumping. How do I do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Next Loop

Rather than use a go add an if

Do while

if condition then

end if
loop

"Mike H." wrote:

If I am in a while or for loop and I have a statement like this:

if 1=1 then
'Go to next iteration of for loop or change cells and go back to top of
while loop
end if


What is the syntax for continuing the loop at this point. Right now, I
create spaghetti code by saying to goto a label like

Goto NextLoop

and then at the bottom of the loop right before the next or loop line, I
have a line:
NextLoop:

But I want to avoid all this goto jumping. How do I do this?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Next Loop

Here is an example of a While Loop
Do While True
Line Input #ff, Line
If Line Like "*rofit Center Totals:*" Then
GoTo OutofLoop
End If
If Len(Line) = 0 Then
GoTo MoreLoop
ElseIf Line Like "*lass Name(ID):*" Then
GoTo MoreLoop
end if
'additional code here if the above jumps did not jump me somewhere
MoreLoop:
Loop
OutofLoop:




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Next Loop

Do While True
Line Input #ff, Line
If Line Like "*rofit Center Totals:*" Then
Exit Do
End If
If Not Len(Line) = 0 Then
If Not Line Like "*lass Name(ID):*" Then
'additional code here
End If
End If
Loop



--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mike H." wrote in message
...
Here is an example of a While Loop
Do While True
Line Input #ff, Line
If Line Like "*rofit Center Totals:*" Then
GoTo OutofLoop
End If
If Len(Line) = 0 Then
GoTo MoreLoop
ElseIf Line Like "*lass Name(ID):*" Then
GoTo MoreLoop
end if
'additional code here if the above jumps did not jump me
somewhere
MoreLoop:
Loop
OutofLoop:








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Next Loop

That is what I was looking for:
Exit Do
Is there also:
Exit For?


Thanks...

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Next Loop

I was having trouble with Boorlean if not... stuff before and thought maybe
it wasn't available in this language either. But I'll have to make sure i
write it correctly then use it. Thanks.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Next Loop

There is.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mike H." wrote in message
...
That is what I was looking for:
Exit Do
Is there also:
Exit For?


Thanks...



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 471
Default Next Loop

Is there any syntax like

continue for

that would perform another iteration of the loop? Sometimes it is not
always practical to have the if...then... to cause the loop to run or not.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Next Loop

Why not? You can always wrap that code into a procedure and call that.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mike H." wrote in message
...
Is there any syntax like

continue for

that would perform another iteration of the loop? Sometimes it is not
always practical to have the if...then... to cause the loop to run or not.






  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Next Loop

Do While True
Line Input #ff, Line


May not apply here, but using EOF was commonly used back in the dark ages:

Do While Not EOF(1)
Line Input #1, x
' etc...
Loop

--
HTH
Dana DeLouis


"Mike H." wrote in message
...
Here is an example of a While Loop
Do While True
Line Input #ff, Line
If Line Like "*rofit Center Totals:*" Then
GoTo OutofLoop
End If
If Len(Line) = 0 Then
GoTo MoreLoop
ElseIf Line Like "*lass Name(ID):*" Then
GoTo MoreLoop
end if
'additional code here if the above jumps did not jump me
somewhere
MoreLoop:
Loop
OutofLoop:




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 0 March 27th 07 11:17 PM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 05:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"