Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default continue statement in a loop


Hi,

I found the "continue" statement in VB documentation but I think it was
only for .NET, it doesn't seem to compile with Excel and VBA. Is there a
way to do this?

I have some code in Java I am trying to use in macro. I'm looking for
the Java equivalent of:


Code:
--------------------

for (int i=0; i<someLength; i++) {
// do some stuff

if (condition) {
continue;
}

// more stuff
}

--------------------

I haven't done VB in a while but I was thinking perhaps a goto
statement may work. Any suggestions on this? Thanks a lot


--
rozner
------------------------------------------------------------------------
rozner's Profile: http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=391982

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 692
Default continue statement in a loop

Sounds like you are looking for an If....Then.....Else....End If
(put in your own conditions)

If Range("A1") = 5 then
' your code to do if 1st condition is true
Elseif y = x then
' your code to do if 2nd condition is true
Else
' your code to do if all condition(s) are false
End If

The For ... Next loop

For i = 0 to 100 step = 1 (do not need step = 1 if you are indexing by 1)
' your code

Next

--
steveB

Remove "AYN" from email to respond
"rozner" wrote in
message ...

Hi,

I found the "continue" statement in VB documentation but I think it was
only for .NET, it doesn't seem to compile with Excel and VBA. Is there a
way to do this?

I have some code in Java I am trying to use in macro. I'm looking for
the Java equivalent of:


Code:
--------------------

for (int i=0; i<someLength; i++) {
// do some stuff

if (condition) {
continue;
}

// more stuff
}

--------------------

I haven't done VB in a while but I was thinking perhaps a goto
statement may work. Any suggestions on this? Thanks a lot


--
rozner
------------------------------------------------------------------------
rozner's Profile:
http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=391982



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default continue statement in a loop

That looks like some variation of C.

You could just do:

dim i as long
dim SomeLength as long

somelength = 12 'whatever???

for i = 1 to somelength step 1
'do some stuff
if conditionstatement = true then
'do nothing
else
'do more stuff
end if
next i

(Just a guess, though. I don't speak the C.)

rozner wrote:

Hi,

I found the "continue" statement in VB documentation but I think it was
only for .NET, it doesn't seem to compile with Excel and VBA. Is there a
way to do this?

I have some code in Java I am trying to use in macro. I'm looking for
the Java equivalent of:

Code:
--------------------

for (int i=0; i<someLength; i++) {
// do some stuff

if (condition) {
continue;
}

// more stuff
}

--------------------

I haven't done VB in a while but I was thinking perhaps a goto
statement may work. Any suggestions on this? Thanks a lot

--
rozner
------------------------------------------------------------------------
rozner's Profile: http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=391982


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default continue statement in a loop

There is no direct equivalent to the continue statemement in JAVA.
Generally, what you show would be done just using a block IF statement

Do While i < someLength
' do some stuff
if Not condition then
' more stuff
end if
i = i + 1
Next

--
Regards,
Tom Ogilvy

"rozner" wrote in
message ...

Hi,

I found the "continue" statement in VB documentation but I think it was
only for .NET, it doesn't seem to compile with Excel and VBA. Is there a
way to do this?

I have some code in Java I am trying to use in macro. I'm looking for
the Java equivalent of:


Code:
--------------------

for (int i=0; i<someLength; i++) {
// do some stuff

if (condition) {
continue;
}

// more stuff
}

--------------------

I haven't done VB in a while but I was thinking perhaps a goto
statement may work. Any suggestions on this? Thanks a lot


--
rozner
------------------------------------------------------------------------
rozner's Profile:

http://www.excelforum.com/member.php...o&userid=25794
View this thread: http://www.excelforum.com/showthread...hreadid=391982



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default continue statement in a loop

Dave:
That looks like some variation of C.


Original Post:
I have some code in Java I am trying to use in macro.


Many say Java looks a lot like C, so you are not alone in your assessment
<g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
That looks like some variation of C.

You could just do:

dim i as long
dim SomeLength as long

somelength = 12 'whatever???

for i = 1 to somelength step 1
'do some stuff
if conditionstatement = true then
'do nothing
else
'do more stuff
end if
next i

(Just a guess, though. I don't speak the C.)

rozner wrote:

Hi,

I found the "continue" statement in VB documentation but I think it was
only for .NET, it doesn't seem to compile with Excel and VBA. Is there a
way to do this?

I have some code in Java I am trying to use in macro. I'm looking for
the Java equivalent of:

Code:
--------------------

for (int i=0; i<someLength; i++) {
// do some stuff

if (condition) {
continue;
}

// more stuff
}

--------------------

I haven't done VB in a while but I was thinking perhaps a goto
statement may work. Any suggestions on this? Thanks a lot

--
rozner
------------------------------------------------------------------------
rozner's Profile:

http://www.excelforum.com/member.php...o&userid=25794
View this thread:

http://www.excelforum.com/showthread...hreadid=391982

--

Dave Peterson



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
for loop with if statement Steve Excel Worksheet Functions 1 February 17th 10 07:56 PM
If statement - Loop? George Excel Discussion (Misc queries) 1 March 14th 06 07:06 AM
Loop including IF statement yalex[_7_] Excel Programming 1 July 8th 04 03:07 PM
For Loop and If Statement question jacqui[_2_] Excel Programming 0 February 13th 04 04:17 PM
Do Until loop with if statement Sandy[_3_] Excel Programming 4 July 17th 03 11:06 AM


All times are GMT +1. The time now is 04:27 PM.

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

About Us

"It's about Microsoft Excel"