SRL Archive - C/C++ Help and Tutorials

Why isn't this working....


Runescapian321

2008-01-10 17:11:50

Well yeah I have another assignment, I have to make something that 8 rows of 8 *'s in each row. However, I have to use nested for loops. So I made this

#include "stdafx.h"
#include "genlib.h"
#include "simpio.h"

int main()
{
int i, j;
for(i=1;i<=8;i=i++);
{
for(j=1;j<=1;j=j++);
{
printf("********");
}
printf("\n");
}
}

It only returns one lines of *'s, why? It should be doing the first loop 8 times and the second loop once every time it does the first loop, but it seems that they each only do their jobs once…

Anyone?

Yakman

2008-01-10 17:56:23

look very closely here


for(i=1;i<=8;i=i++);
for(j=1;j<=1;j=j++);

seen it yet?

for(j=1;j<=1;j=j++);

its that semicolon at the end, remove that from both of them and it should work

this is an old trick, its caught out many beginner programmers before, I know how it feels to have this happen to you.. :)

Runescapian321

2008-01-10 19:23:31

:duh: Thanks!

Yup, now it works. So THATS why sometimes something doesn't work but I'm pretty sure it should. I then end up re-writing it, and it ends up workking, then I have no idea what I changed :p

Bobarkinator

2008-01-14 10:52:30

On for loops its brackets or nothing ;)