while (true) loop

I am writting a program that gives us the whole and the decimal part of the number given by the user. The program then asks the user if he wants to restart the program, this is a that of the code and if someone could please explain me what does the while(true) loop do.

1
2
3
4
5
6
7
8
9
10
11
12
  while (true) 
	{

		if (started != -1) 
		{
		cout << "Do you want to restart the program? (1 - yes, 0 - no)" << endl;
		while (started < 0 || started > 1)
                cin >> started;
		if (started == 0)

		break;
	    }
well from my understanding of it (there might be a more correct way) a condition in an if, else if, while, do-while, and for is ultimately evaluated to true or false. for example: if(x==1)... if x does indeed x = 1, then the condition is evaluated to true (because it is true that x = 1). however if x ='s lets say 5, then it would be false (because it is false that x == 5). so the while true loop basically means that the condition is evaluated to true and will be always executed
while (true) means that the loop will iterate forever, unless some command inside the loop forces the loop to end. In this case, the break; on line 11 will force the loop to end.

By the way, you really should indent your code sensibly. It would be much easier for you - and for anyone else reading your code - to see the flow of control at a glance.
while(true) will loop indefinitely until the break statement. The break statement will break the inner most loop or switch. In this case it will break out of the while loop.

Alternatively, I did this for you last night for the same problem using a do-while loop: http://www.cplusplus.com/forum/beginner/127236/
Thank you for your help!
Topic archived. No new replies allowed.