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:
Sum = 0
FOR even = 2 T0 50 STEP 2
Sum = Sum + Even
PRINT "The even numbers are:"; Sum
How The Program WorksWe 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
Print "The even numbers are :"; Even
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