Jump to content
  • 0
MontyHall

How to use int variables in for loop?

Question

I thought this would be legal code

 

100 for b% = 0 to 10

110 print b%

120 next b

 

But I get a syntax error at line 100.  Is this not possible?  Or how to do it correctly.

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I don't think you can create Integer variables. They will always be floating point or strings.

Your example would be

Quote

100 FOR B = 0 TO 10

110 PRINT B

120 NEXT B

String variable names are followd by a dollar sign.

Quote

A$ = "HELLO, WORLD"

Of course you can not do counting on strings 🙂

Share this post


Link to post
Share on other sites
  • 0

You can't use integer variables for FOR loops, you have to use regular real variables.

Keep in mind: integer variables are still stored as floating point and actually introduce a performance hit by having to do rounding all the time. That's why you don't want to bother with one for a loop variable. Only use them when you absolutely need arithmetic results to be automatically rounded.

  • Like 3

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Please review our Terms of Use