Question: I like to make GDB set a break point when a variable equal some value I set, I tried this example:

```
#include <stdio.h>
main()
{ 
     int i = 0;
     for(i=0;i<7;++i)
        printf("%d\n", i);

     return 0;
}

```

Output from GDB:

```
(gdb) break if ((int)i == 5)
No default breakpoint address now.
(gdb) run
Starting program: /home/SIFE/run 
0
1
2
3
4
5
6

Program exited normally.
(gdb)

```

Like you see, GDB didn't make any break point, is this possible with GDB?

Answer: 
You can use a watchpoint for this (A breakpoint on data instead of code).

You can start by using `watch i`.  

Then set a condition for it using `condition <breakpoint num> i == 5`

You can get the breakpoint number by using `info watch`
There are hardware and software watchpoints. They are for reading and for writing a variable. You need to consult a tutorial:

<http://www.unknownroad.com/rtfm/gdbtut/gdbwatch.html>

To set a watchpoint, first you need to break the code into a place where the varianle i is present in the environment, and set the watchpoint.

`watch` command is used to set a watchpoit for writing, while `rwatch` for reading, and `awatch` for reading/writing.