# Thread: DDD conditional breakpoint : expression error

1. ## DDD conditional breakpoint : expression error

I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
I just get a message : junk at the end of expression

Code:
```bool
won(void)
{
int prevpos = 0;
int count = 0;

for (i = 0 ; i <= d -1 ; i++)
{
for (j = 0 ; j <= d -1; j++)
{
prevpos = board[i][j];
if(board[i][j] < prevpos )
count++;
if (count == (d*d)-1)
return true;
}

}
return false;
}```
hopefully someone can shed a light on this.

2. Originally Posted by lamko
I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
I just get a message : junk at the end of expression

Code:
```bool
won(void)
{
int prevpos = 0;
int count = 0;

for (i = 0 ; i <= d -1 ; i++)
{
for (j = 0 ; j <= d -1; j++)
{
prevpos = board[i][j];
if(board[i][j] < prevpos )
count++;
if (count == (d*d)-1)
return true;
}

}
return false;
}```
hopefully someone can shed a light on this.

for (i = 0; i <= d - 1; i++) is much simpler like this.... for (i = 0; i < d; i++) .... the behaviour is exactly the same.

3. Never used DDD, but: are you actually typing "won if i==2" in the box? If you want a conditional breakpoint, a quick glance at the manual suggests you should just use "i==2". If you are trying to do something else, maybe be a bit more specific about what you're trying to achieve.

4. To build on CommonTater's suggestion for loop improvement ... is this what you actually intended? Because this will never be true.

Code:
```    prevpos = board[i][j];
if(board[i][j] < prevpos )
...```

5. Originally Posted by Matticus
To build on CommonTater's suggestion for loop improvement ... is this what you actually intended? Because this will never be true.

Code:
```    prevpos = board[i][j];
if(board[i][j] < prevpos )
...```
Nice catch! I looked right at that and missed it...

6. d is a argument to the program which sets the dimension of the fifteen game.
The function isn't working yet, so i'll think and you guys confirmed my error but thats why I want to use gdb. I'm not so much of a coder but after some debugging I'll get the stuff right. Just need some more experience.

I've tried it and isnt working. I just want to get the outher loop to the third run : i=2 if tried different syntax. I'll test in DDD but I want to use it in codeblocks.
You mean this manual ?
GDB Internals

7. Originally Posted by lamko
I've just read te book The art of debugging with GDB, DDD and Eclipse, but I just can't find out what I'm doing wrong:

I'm using DDD i've set a breakpoint at the first for loop. Then I fill in at the properties of the breakpoint the expression : won if i==2 and click apply
I just get a message : junk at the end of expression
That DDD is just a GUI front-end to gdb, and what you are trying to do is known as setting a watchpoint in gdb.
To do that in gdb, set breakpoint on won(), step into it, and set breakpoint at the line no. in won() when i == 2.
Code:
```(gdb) b won          /* put a breakpoint on won() */
(gdb) r              /* run the program */
(gdb) b 7 if i=="3"  /* set breakpoint at line no 7 of won() when i == 3 */```

8. I've tried what you recommended but :
The breakpoint just start at position zero with value zero. What I want to do is just simply put, go for example i=3 and j=2 then I want to read the value from the array. After that I want to go a couple of line further to get i =3 and j =3 and I want to get that value. So to put it really clear I donīt want to next next the whole array just to get at the good position.

If I step into the function all values return to zero. If I'll stay in main it's working just as expected maybe I'm running at some technical limitations anyone a good book or link on this matter.

9. Originally Posted by CommonTater
Nice catch! I looked right at that and missed it...
Thanks! Someone on this board (I think it was laserlight) recently mentioned how it's easier to write code than to read code. My short time on this board has shown that this is largely true.

10. With a breakpoint on the beginning of the loop and one on the end + continue 15x i'll get exactly at the right position !