473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Summing Odds and Evens

Not to step on anyone, but in reference to this thread on summing odds and evens, why not just use the 'continue' statement? So adding up the odds would look something like this:

-on some event-
Expand|Select|Wrap|Line Numbers
  1.         Dim counter, sum As Short
  2.         sum = 0
  3.         For counter = 1 To 99
  4.             If counter Mod 2 = 0 Then Continue For
  5.             sum += counter
  6.         Next
  7.         lblOdd.Text = sum
  8. end sub
You would just have to define the array from an input.
Apr 5 '07 #1
8 2323
Killer42
8,435 Expert 8TB
Not to step on anyone, but in reference to this thread on summing odds and evens, why not just use the 'continue' statement?
Visual Basic has a continue statement? That's news to me. What version of VB?
Apr 6 '07 #2
Visual Basic has a continue statement? That's news to me. What version of VB?
VB 2005 is the first ver. to incorporate it (that I know of).
Apr 9 '07 #3
Killer42
8,435 Expert 8TB
VB 2005 is the first ver. to incorporate it (that I know of).
So, I'm guessing that it skips to the next iteration of the loop?

The language I use on the mainframe, called Natural, has such a statement (ESCAPE TOP). This has always been one of its best features, and one which I have greatly missed in other languages.
Apr 9 '07 #4
Killer42
8,435 Expert 8TB
To get back to the original question (not that the poster will see any of this, I suppose)...

If anyone's interested, it seems to me that just about the most efficient method (assuming there isn't a way to do it in a single calculation) would be to use an IF/ELSE construct. For example:
Expand|Select|Wrap|Line Numbers
  1. Dim Counter As Long, SumOdd As Long, SumEven As Long
  2. For Counter = 1 To 99
  3.   If Counter Mod 2 Then
  4.     SumOdd = SumOdd + Counter
  5.   Else
  6.     SumEven = SumEven + Counter
  7.   End If
  8. Next
(I'm assuming that the real issue wasn't about a simple 1 to 99 loop.)
Apr 9 '07 #5
Here's the list of new commands.

From M$:
"Continue Statement

Visual Basic now supplies a Continue statement, which immediately skips to the next iteration of a Do, For, or While loop. "
Apr 12 '07 #6
And no, my problem was much more difficult. I just don't expect more experienced people to do my homework for me :) (though, answering a question here and there has been invaluable).
Apr 12 '07 #7
Killer42
8,435 Expert 8TB
Here's the list of new commands.
Thanks, I'll bookmark that one for (probably a lot of) future reference.
Apr 13 '07 #8
Killer42
8,435 Expert 8TB
And no, my problem was much more difficult. I just don't expect more experienced people to do my homework for me :) (though, answering a question here and there has been invaluable).
Uh oh... you said the "H word". Now I'll have to close down the thread and kill you. ;)





In case this is too cryptic, I should point out that there has been considerable (and sometimes heated) heated debate over the handling of homework & coursework questions on TheScripts.
Apr 13 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Yaroslav Bulatov | last post by:
I made an array of 10 million floats timed how long it takes to sum the elements, here's what I got (millis): gcc -O2: 21 Python with numarray: 104 Python with Numeric: 302...
2
by: SunMan | last post by:
Hello! I am trying to create a program that will ask for a user to enter a series of letters (codes) and then print out a table that shows the codes in decending frequency. Only letters will be...
2
by: Targa | last post by:
<input NAME="TAXRATE" onBlur="this.form.TAX.value = (this.form.TAXRATE.value - 0) * (this.form.ITEM1TOTAL.value - 0) + (this.form.ITEM2TOTAL.value - 0) " Size="4"> In my TAX field I get...
7
by: Hank | last post by:
I have a report-summing problem using Access 2000. When a section runs over the end of the page, sometimes a detail gets picked up twice. Example: Customer Header XYZ Company Detail Section...
1
by: siva prasad | last post by:
hello, i have an appplication in which when i click a button then all the odds in a website are to be displayed. so i need Regular Expressions for identifing the odds.i am in the learner stage of...
1
by: Mamatha | last post by:
Hi I want to write regular expression for odds which related to sports in VB.NET. But i don't know how to write regular expression for odds. If anyone knows the solution or any related urls...
2
by: MrL8Knight | last post by:
I am building a simple shopping cart and I am having problems trying to add the costs of the items to generate a total cost. I am new at this so forgive me if my technical verbiage isn’t the...
12
by: neeraj | last post by:
Hi Can any body give me the syntax for summing the elements of the an array , without looping thanks
7
by: lethek39 | last post by:
Hey I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.