[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 264: mysqli_fetch_assoc(): Couldn't fetch mysqli_result
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/mysqli.php on line 326: mysqli_free_result(): Couldn't fetch mysqli_result
Pete's QBASIC Site Discuss QBasic, Freebasic, QB64 and more 2020-04-19T12:35:11-05:00 http://petesqbsite.com/phpBB3/app.php/feed/topic/14831 2020-04-19T12:35:11-05:00 2020-04-19T12:35:11-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38929#p38929 <![CDATA[Re: For/Next/Step]]>

Anyway, it's a disposable program. I only need it to show me bits changing in a memory resident program I created in MASM. It did the job.



Thanks for the reply!

Jj

Statistics: Posted by jejump — Sun Apr 19, 2020 12:35 pm


]]>
2020-04-18T22:49:27-05:00 2020-04-18T22:49:27-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38928#p38928 <![CDATA[Re: For/Next/Step]]>
When you type:

Code:

FOR a = b TO c STEP d  PRINT aNEXT a
QBASIC is actually doing:

Code:

from = bto = cstep = da = fromGOTO Next:For:  PRINT a  a = a + stepNext:  IF a <= to THEN GOTO For
Modifying the loop control variable works but it's also something you should avoid doing (it's a bit dirty.) However, you could do:

Code:

FOR a% = 0 to 7  PRINT 2 ^ a%NEXT a%
Alternatively, you may try using DO...LOOP

Code:

DIM a AS INTEGERa = 1DO  PRINT a  a = a * 2LOOP UNTIL a = 256
EDIT: I didn't look at what you were doing, only what you expected. Just as a side note, A ^ 2 will return the square of A, while you were looking for powers of two, which would be 2 ^ A. Had your initial attempt worked, returned values would be 1 ^ 2 (1,) 2 ^ 2 (4,) 3 ^ 2 (9,) 4 ^ 2 (16,) not 1, 2, 4, 8, etc.

Statistics: Posted by MikeHawk — Sat Apr 18, 2020 10:49 pm


]]>
2020-04-18T07:21:12-05:00 2020-04-18T07:21:12-05:00 http://petesqbsite.com/phpBB3/viewtopic.php?p=38927#p38927 <![CDATA[For/Next/Step]]>
For A = 1 TO 128 STEP A^2
PRINT A
NEXT

To try to achieve the screen output of:

1
2
4
8
16
~~~
128

Instead I get this:

1
1
1
1
1
~~~~ etc,

I ended up doing this:

For A = 1 TO 128
PRINT A
A = A * 2 -1                    ' Definitely need the -1. NEXT instruction increments +1
NEXT

Ditching the use of STEP altogether. This works, but I just wonder why the other way doesn't? I am reasonably sure that I made the former way work years ago, but I was probably using QBX 7 then. Maybe I am forgetting something about the way it should be formatted. I've tried round brackets (A^2) and nothing changed. Anyway, it's working with method 2.

Thanks for the love <3

Jj

Statistics: Posted by jejump — Sat Apr 18, 2020 7:21 am


]]>