loops using "FOR"

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1104
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 453 times
Been thanked: 505 times
Contact:

loops using "FOR"

Postby Steve001 » Mon Dec 05, 2011 8:19 pm

Evening all,

looking to make a counting loop , and wanting some advice please

i am familiar with the following example:

FOR N = 0 TO 10 STEP 1
PRINT N
NEXT N

which will print 1,2,3, etc

It has been so long since i have done any programming,
i am looking for an example

i believe it's

for . . .

end if

i'm a bit lost if somebody can point me in the right direction please


steve
Success always occurs in private and failure in full view.

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 716 times
Contact:

Re: loops using "FOR"

Postby JohnCrow » Mon Dec 05, 2011 9:25 pm

Hi Steve

Its a long time since I did any C programming, Id realy like to get back into it.
If I remember to leave a "FOR" loop the command is "RETURN"

This is a simple example from a C programming book ive got on the shelf

#include <stdio.h>
main()
{
int ctr; /* set variable ctr as integer */

for (ctr = 1; ctr<=10; ctr++) /*start ctr at 1 and increment through loop */

{ printf ("%d \n", ctr) ; } ? * Body Of Loop */

return;
}
Program will print 1 2 3 4 5 6 7 8 9 10 (in a vertical line)

Im sure the guys at Matrix will give you a better answer when they come in.

Hope this is a help
These users thanked the author JohnCrow for the post (total 2):
Steve (Tue Dec 06, 2011 9:12 am) • Steve001 (Tue Dec 06, 2011 1:41 pm)
Rating: 10.53%
 
1 in 10 people understand binary, the other one doesn't !

User avatar
Steve
Matrix Staff
Posts: 3103
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 89 times
Been thanked: 391 times
Contact:

Re: loops using "FOR"

Postby Steve » Tue Dec 06, 2011 9:12 am

(I don't think a better answer is needed!)

User avatar
Steve001
Valued Contributor
Valued Contributor
Posts: 1104
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 453 times
Been thanked: 505 times
Contact:

Re: loops using "FOR"

Postby Steve001 » Tue Dec 06, 2011 1:41 pm

thanks for that , will have a go :D :D

steve
Success always occurs in private and failure in full view.