# Thread: I want to understand this code

1. ## I want to understand this code

Please Guys, this code is from a math program, i want to understand it:
at line 5 what is done to rt?
at line 8 what does continue do?
at line 9 and 11 what is done to rt?

and thanks to you all
Code:
```1    double evaluate(int g)
2    {
3    int u;
4    double rt=0;
5    rt=sys[g][nun];
6    for(u=0;u<nun;u++)
7    {
8    if(g==u) continue;
9     rt-=sys[g]*back;
10   }
11   rt/=sys[g][g];
12   return rt;
13   }```
note that sys and back are defined previously as double **sys, *back;

2. How about you saying what you think happens (or try running the code in a debugger and seeing what happens)

3. sys is a two-dimensional array. sys[g][nun] holds some value which is assigned to rt in line 5.

continue will break-out of the for-loop. That one should have been easy to look-up in any begining C++ book. Or, online... cppreference.com is a good place to look-up keywords and standard library functions.

Your book should have -= too. Or, at least +=.
x -=2 is the same as x = x - 2.

You might need to study arrays and pointers too. (And, pointers to arrays.)

4. actually continue will not break out of the loop, but it will go to the next iteration of the for loop, thus skipping the "rt-=sys[g]*back;" part.

5. Originally posted by epic
actually continue will not break out of the loop, but it will go to the next iteration of the for loop, thus skipping the "rt-=sys[g]*back;" part.
And in this case it is also bad style.

Code:
```6 for(u=0; u < nun; u++)
8   if(g != u)
9     rt-= sys[g] * back;
10```
would have done the trick.

6. if you indent the code it might help a little to understand.
Code:
```
double evaluate(int g)

{
int u;
double rt=0;
rt=sys[g][nun];

for(u=0;u<nun;u++) {
if(g==u) continue;
rt-=sys[g]*back;
}

t/=sys[g][g];
return rt;
}```

7. Thank you very much guys, i didn't expect you to be very kind to help me, Thanks for
gamer4life687
darksaidin
epic
DougDbug
and for Salem although you weren't helpful

I really understood the code now, and specially when i understood the function of "Continue", when darksaidin gave us a similiar code.

8. > and for Salem although you weren't helpful
Many others disagree
But then again, I seldom go for the degree of spoon feeding which the others do, which in the long run doesn't actually help you figure things out for yourself.

So if you really want to learn, you'll get into the habit of actually trying stuff for yourself, rather than running to the message boards every time you have even the tiniest problem.

Or carry on as you are and forever remain as your name suggests, a bad programmer.

9. > Or carry on as you are and forever remain as your name suggests, a bad programmer.

That's so funny,
but, you know, when i want to learn, i do what you are saying, i'm even following a great plan to improve my self in many fields : Java, Oracle, assembly(soon), C++(soon)
but when i don't have time, i ask for help in some clubs. For example the previous code is for a Numerical Methods theorem, i found a similar code over the internet, and i wanted to modify it so it can satify my needs, and it was just two days to submit my work. I needed quick help at that time, and this is what i got with the great people here and in other clubs too. and i have done a great job for my course, that job wasn't possible in this small period of time, to study C++ from zero, until i'm able to write the program. it's really impossible.

In short, i'm improving myself with a hard-work daily plan in many fields, and i just needed to understand that code quickly for some purposes.

Thank you
Yours Sincerely
BaD pRoGrAmMeR

10. Well I wouldn't recommend getting into it with Salem. He knows his stuff and if he tells you to do a certain thing, you probably would be wise in heeding his advice.

Spoon feeding, although I do it at times, does not help you at all. In fact IMHO sometimes it complicates matters because other people's code can be hard to read even if well commented.
So you might get confused simply because of the way it was coded and not because of the principle involved.

Popular pages Recent additions