# Incrementing to the next variable in FOR...NEXT loop.

#### mortifyu

##### New Member
Hello once again Guru's.

I am trying to compare variable values and want to increment to the next variable to check. Although this will obviously not work, I want to do something such as...

Code:
``````.
.
.
b0=120

for b1=2 to 20
if bXX=b0 then
high c.4
else
low c.4
endif
inc bXX
next
.
.
.``````
Your help is as always much appreciated Guru's.

Regards,
Mort.

#### hippy

##### Senior Member
It will help if you can explain exactly what you are wanting to do or achieve. The example you gave would work if variable 'bXX' were replaced with an actual variable, even if 'b0' or 'b1' but might not give the desired result. It's that desired result you really need to describe.

#### mortifyu

##### New Member
Hi Hippy,

Sorry, I thought that was clear. As per my coded example, what I am trying to ask is...

Compare the value of b2 against b0. Once this has been determined, increment to b3 and now compare b3 to b0, increment to b4 and compare to b0 and so on.

I hope this clarifies my question.

Regards,
Mort.

#### oracacle

##### Senior Member
you would need to use the bptr and @bptrinc.
seems to work in simulator
Code:
``````b0 = 120
bptr = 2    'this will start reading variable from b2
for bptr = 2 to 20
if @bptrinc = b0 then 'this compares the variable to b0 and then increases for the next loop
high c.4
else
low c.4
end if
next``````

#### Aries

##### New Member
Code:
``````...
for bptr = 2 to 20
if @bptrinc = b0 then 'this compares the variable to b0 and then increases for the next loop
high c.4
else
low c.4
end if
next``````
I don't think you want @bptrinc in the code - it will increment bptr twice (once in the loop, once with the "inc"
@bptr should do

#### oracacle

##### Senior Member
yeas, that true. Completely missed that, changing the @bptrinc out for @bptr will resolve the issue