Loops crashing program

Hello! So I was using a while loop to create a rectangle and it crashes my program every time. I have set up breakpoints and gone through it several times and it should do the trick but it just crashes.

I have already come up with another solution to make a rectangle with 2 for loops instead but I just want to know why this piece of code crashes the program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	int x = 295;
	int y = 295;

	while (x < 300)
	{
		if (y < 300)
		{
			gfx.PutPixel(x, y, 255, 255, 255);   
			x++;
			if (x == 300)
			{                         //These are the lines that 
				x = 295;          //crashes the program, if
				y++;              //I remove those lines the 
			}                         //program runs fine.
		}
	} 
	
> it just crashes.
No, it freezes.

> I have set up breakpoints and gone through it several times and it should do the trick but it just crashes.
the debugger will help you find the problem. It will not solve the problem by itself.


Suppose that y=300 and x=295, and follow the code starting from line 4.
Okay I see it now. So simple but my head was stuck because I was sure it should be working. And with the breakpoints i meant I followed the executions line by line until y=300 and I just couldnt understand why the program freezed.

Thank you
Topic archived. No new replies allowed.