repeat construct

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

repeat construct

Post 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]
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post 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.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Post by 01000101 »

int count = 8;
while(count--){do_something();}

I don't think that is very difficult?
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Post 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 .
Laksen
Member
Member
Posts: 140
Joined: Fri Nov 09, 2007 3:30 am
Location: Aalborg, Denmark

Post by Laksen »

Pascal doesn't have an explicit iterative repeat construct. Instead the repeat in pascal goes like
repeat
"statements"
until "expression";
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post 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++)
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Yup

Post 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
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Post by DeletedAccount »

Craze Frog
Member
Member
Posts: 368
Joined: Sun Sep 23, 2007 4:52 am

Post by Craze Frog »

FASM has a repeat macro, which simply repeats the given instructions (no loops involved, they are inserted multiple times).
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

hi Craze Frog ,

Post 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 ():
  }
}
DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

Repeat construct

Post 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 

DeletedAccount
Member
Member
Posts: 566
Joined: Tue Jun 20, 2006 9:17 am

he fixed a bug ...

Post by DeletedAccount »

he he fixed a bug 8)
Post Reply