BASIC Program to Find Even Numbers Using FOR TO NEXT statement

Looking for some examples of BASIC programming language? Then here's a BASIC Program to find even numbers using the FOR TO NEXT statement.

There are several BASIC programming language statements and commands that can be employed in arithmetic computations and much more.

The program below tries to find the even numbers between 0 and 50 and then prints the result out to the screen.

Here's what it looks like:

Program Code

CLS
Sum = 0
FOR even = 2 T0 50 STEP 2
Sum = Sum + Even
NEXT even
PRINT "The even numbers are:"; Sum
END

How The Program Works

We begin by clearing the screen with the CLS statement and then proceed to initialize our variable Sum to 0.

At 0, we ensure that there is no value currently in SUM that may give us an unexpected result.

Next, we set a looping condition using the FOR TO NEXT statement in BASIC.

Here, the variable Even is initialized to 2 and stopped at 50, hence that is the range between which our even numbers will be selected.

On the other hand, you can choose to print the even numbers to the screen instead of adding them together and assigning it to sum. Thus that section of the program will append to become.

For even = 2 TO 50 STEP 2
Next even
Print "The even numbers are :"; Even
End.

Whichever is the case, you'll get a set of even numbers displayed to the screen and the total sum of the numbers generated.

Conclusion:

This simple BASIC Program to Find Even Numbers Using FOR TO NEXT statement can help you write more program codes in future and even program in complex programming languages. Now take the next step and give it some practice.


Also Read: BASIC Program to Compare The Greatest of Three Numbers
                   Pascal Program of Matrix Multiplication
                   BASIC Program to Create Multiplication Table

Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:


HTML Link Code:

BB (forum) link code:

Comments