ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Next Loop (https://www.excelbanter.com/excel-programming/395364-next-loop.html)

Mike H.

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?


Don Guillett

Next Loop
 
Provide details of BOTH what you want to do and the full code you have
tried.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Mike H." wrote in message
...
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?



joel

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?


Mike H.

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:





Bob Phillips

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:







Mike H.

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


Thanks...


Mike H.

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.



Bob Phillips

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...




Mike H.

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.



Bob Phillips

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.





Dana DeLouis

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:






All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com