Android Question SERVICE problem with nested "FOR"

gemasoft

Member
Licensed User
Longtime User
I have in a service this code:

dim a as int
dim b as int

for a =0 to 10

for b=0 to 10
next b
next a

And when start the application using this code as service ocurrs an error.-

If i change 1 for with DO WHILE, the code is ok.-

I can think that this problem is a bug in the compiler?

thanks-
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

You can not use the variable's letter in your Next. It should be only Next

B4X:
Dim a as Int ' this could be omitted
Dim b as Int ' this could be omitted

For a=0 to 10

  For b=0 to 10
    Log("a: " & a & "/" & "b: " & b)
  Next

Next

PS: in your IDE's options, you could check "Test compile when saving". It would have shown the error before you spend the time to try
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Unfortunately.

No. It is like it is described int he documentation.

But you can write it like this to help you seeing which for-loop you are in.

B4X:
Dim a as Int ' this could be omitted
Dim b as Int ' this could be omitted
For a=0 to 10
  For b=0 to 10
    Log("a: " & a & "/" & "b: " & b)
  Next ' b
Next ' a
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
No. It is like it is described int he documentation.

But you can write it like this to help you seeing which for-loop you are in.

B4X:
Dim a as Int ' this could be omitted
Dim b as Int ' this could be omitted
For a=0 to 10
  For b=0 to 10
    Log("a: " & a & "/" & "b: " & b)
  Next ' b
Next ' a


Thanks Manfred.

I can also write a more descriptive string (Next ' c - customer) but an automatic insertion would be useful:
I write:
For A = ...
and pressing Enter
Next A (case sensitive too)
:)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Thanks Manfred.

I can also write a more descriptive string (Next ' c - customer) but an automatic insertion would be useful:
I write:
For A = ...
and pressing Enter
Next A (case sensitive too)
:)

Yes, that would be great
 
Upvote 0
Top