for... next loop

Beta Testing discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Jean-Paul59
Posts: 13
Joined: 10 Sep 2011 20:37
Location: FRANCE - Pays de la Loire

for... next loop

#1 Post by Jean-Paul59 » 07 Jan 2013 17:04

Hello,

For learning and testing "trigon" library, i write a very smal program :

dim angle as float

main:
for angle = 0 to 3.14 step 0.01
......
next

I can't make HEX, I have errors : 'Syntax error : Expected "integral type" but "float" found' and 'Argument is out of range "0" to "float"'.
I don't understand, "integer" can't have decimal value ? how can I do a loop with decimal value ?
Thank you for all
Jean-Paul

Jean-Paul59
Posts: 13
Joined: 10 Sep 2011 20:37
Location: FRANCE - Pays de la Loire

Re: for... next loop

#2 Post by Jean-Paul59 » 07 Jan 2013 17:27

Excuse me,
I see I write in a wrong thread,
I also have some difficulty with english ! not only with MikroBasic.
Jean-Paul

Seniorlemuren
Posts: 125
Joined: 25 Sep 2012 23:51
Location: Sweden

Re: for... next loop

#3 Post by Seniorlemuren » 07 Jan 2013 17:29

I dont know the syntax in basic. I use C. But the princip is this.

dim angle as float
dim i as integer

main:
for i = 0 to 314 step 1
angel = i div 100
......
next
Last edited by Seniorlemuren on 08 Jan 2013 11:26, edited 1 time in total.
Regards

Plain common sense is not very common.

Jean-Paul59
Posts: 13
Joined: 10 Sep 2011 20:37
Location: FRANCE - Pays de la Loire

Re: for... next loop

#4 Post by Jean-Paul59 » 08 Jan 2013 10:44

OK,
I try this method, it's good, I can make an HEX
Thank for your help
Jean-Paul

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: for... next loop

#5 Post by filip » 08 Jan 2013 12:13

Hi,

The for loop parameters can be integers only, you cannot use floating point numbers.

Regards,
Filip

Jean-Paul59
Posts: 13
Joined: 10 Sep 2011 20:37
Location: FRANCE - Pays de la Loire

Re: for... next loop

#6 Post by Jean-Paul59 » 08 Jan 2013 14:34

thank you,

I found an other error in my program :

dim af as float
dim i as integer

for i = 0 to 628

af = i / 100 ' is wrong !

af = i
af = af / 100 ' is correct

next i

Jean-Paul

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing”