The repeat statement

Post your requests and ideas on the future development of mikroBasic.
Post Reply
Author
Message
Sidharta
Posts: 233
Joined: 01 Sep 2005 10:53
Location: Spain

The repeat statement

#1 Post by Sidharta » 05 Sep 2005 17:18

There are a lot of times we use a loop just to repeat a finite number of times
It would be usefull to have a new loop statement like this


sub procedure
repeat 8

' everything we want to do 8 times


end repeat



end sub

sometimes is clearer than the rest of loops

anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

#2 Post by anton » 05 Sep 2005 17:22

sub procedure
repeat 8

' everything we want to do 8 times


end repeat



end sub
Then it won't be Basic anymore :wink:
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

Steve
Posts: 233
Joined: 19 Aug 2004 02:33
Location: North Carolina

#3 Post by Steve » 06 Sep 2005 01:51

That's exactly what the for loop is for.

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#4 Post by xor » 07 Sep 2005 01:44

The FOR-NEXT loop permits use of variables for start and stop points which is important to some applications.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

Sidharta
Posts: 233
Joined: 01 Sep 2005 10:53
Location: Spain

I don't intend supressing the for loop

#5 Post by Sidharta » 07 Sep 2005 18:23

I think repeat allows to avoid using a variable .
Probably in assembler it allows a more efficient code.
You don't have to worry about limits in the for loop
Of course it's possible to live without it

Steve
Posts: 233
Joined: 19 Aug 2004 02:33
Location: North Carolina

#6 Post by Steve » 07 Sep 2005 19:11

You will still need a variable to keep track of the number of times you wish to repeat the loop.

It would be redundant to have two constructs that do the exact same thing.

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#7 Post by xor » 07 Sep 2005 20:44

For-Next is a very flexible type of loop that also does simple Repeat.

Code: Select all

FOR a = b TO c 
    'Some more code
NEXT a
Also:

Code: Select all

FOR a = b TO c STEP d
    'Some code
NEXT a
b is the start variable value and c is the stop variable value (no redundancy here). Using variables instead of constants allows for a flexible Repeat sequence and saves on code size.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

Post Reply

Return to “mikroBasic Wish List”