Page 1 of 1

repeat construct

Posted: Thu May 08, 2008 9:02 am
by DeletedAccount
I just thought of a construct , Although it is not that useful it does save some keystrokes

eg

Code: Select all


repeat 8
{
   do_somthing();
}

means to repeat do_something 8 times . The grammar for the repeat construct is

RepeatStatemet -> "repeat" Expression Block

may be we can make use of a special variable to mark the current iteration.
eg

Code: Select all


repeat  10
{
   array[current_iteration] = 0;
} 
I think this is far natural than

Code: Select all

for(int k= 0 ; k < 10; k++)do_something;
I am back ...[/code]

Posted: Thu May 08, 2008 9:07 am
by Korona
I think Pascal has a construct like that. As you said it is not that useful so I do not miss it in my programming language. for-Loops are fine.

Posted: Thu May 08, 2008 9:11 am
by 01000101
int count = 8;
while(count--){do_something();}

I don't think that is very difficult?

Posted: Thu May 08, 2008 9:12 am
by DeletedAccount
Yes , i think pascal has. I do not remember exactly, but i only have a reading familiarity with pascal . I do not use pascal much .

Posted: Thu May 08, 2008 9:41 am
by Laksen
Pascal doesn't have an explicit iterative repeat construct. Instead the repeat in pascal goes like
repeat
"statements"
until "expression";

Posted: Thu May 08, 2008 2:27 pm
by B.E
If you cange the syntax just a bit to "repeat (10)..." you could use a macro for this

Code: Select all

#define repeat(x) for(int i=0;i<x;i++)

Posted: Thu May 08, 2008 4:43 pm
by Combuster
Repeat is an integral part of the LOGO programming language. In fact, that's the only thing you can use as it doesn't have for loops.

Yup

Posted: Thu May 08, 2008 11:12 pm
by DeletedAccount
Logo is more powerful than i thought , Check out the ucblogo website . Please take a look at the series Computer Science Logo style ... Excellently written set of books

Posted: Fri May 09, 2008 12:02 am
by DeletedAccount

Posted: Sat May 10, 2008 1:06 pm
by Craze Frog
FASM has a repeat macro, which simply repeats the given instructions (no loops involved, they are inserted multiple times).

hi Craze Frog ,

Posted: Sat May 10, 2008 8:18 pm
by DeletedAccount
I do not think macros are a part of the language , they just simply perform text substitution ..if repeat is a macro try somthing like this and find the size of the executable ..

Code: Select all

#include <limits.h>

repeat INT_MAX
{
   repeat INT_MAX
  {
    do_something ():
  }
}

Repeat construct

Posted: Sun May 11, 2008 10:01 pm
by DeletedAccount
As an example of how easy it is to add repeat constuct to an existing programming language i have provided an implementation of basic like language known as SanBasic with support for repeat construct ... As an example

Code: Select all


repeat  4
  print "Mu ha ha ha "
rend 


he fixed a bug ...

Posted: Sun May 11, 2008 10:45 pm
by DeletedAccount
he he fixed a bug 8)