Repeating same calculations with incremental variable

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

Repeating same calculations with incremental variable

Post by LEGRAND »

Can you tell me how it is possible to use a loop to make several time the same calculation:exemple
Y=SIN(A)
with A= 2,3,4,5 etc
something like
FOR N=1 TO 10
PRINT Y=SIN(N)
NEXT N
Many thanks in advance
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You cannot PRINT a variable definition, but you get no error either!

Your code:

FOR N = 1 TO 10
PRINT Y = SIN(N)
NEXT N

Print the variable value:

FOR N = 1 TO 10
Y = SIN(N)
PRINT Y
NEXT N

OR just print the function return:

FOR N = 1 TO 10
PRINT SIN(N)
NEXT N


SIN and COS use radian values up to 2 * PI = 6.28. Going above that creates negative values.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
LEGRAND
Coder
Posts: 49
Joined: Wed Jul 30, 2008 7:57 am

formula with incremental values

Post by LEGRAND »

THANKS A LOT!
Post Reply