Question: Boolean While Loop...

My friend wrote this code for me to understand some topics I asked him about. For his sake (i've asked far too many questions) I want to present this question here.

Could someone explain to me in human language what LINE 14 is proclaiming when it exclaims:

while (out_of_order){

I'm not what the while statement is declaring here.
I'm new to boolean logic, so please be as specific as possible. I understand that the variable is being held as true, but I don't understand what the conditions mean for the while statement.

1. Is the while statement saying "loop while out_of_order is false?" If that's the case then...

2. Why is it then said that out_of_order is false during the IF function?

Here's the rest of the code (without some parts on either end...):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

int main() {
	int v1, v2, v3;		// variables for type int
	cin>>v1>>v2>>v3;	// reading v-variable
	
	bool out_of_order;	// 
	
	// Sort it into ascending order
	// where v1 < v2 < v3
	out_of_order = true;	// MIGHT be out of order variable is BOOLEAN
	while(out_of_order) {
		out_of_order = false;	// out_of_order FALSE if
		if(v1 > v2) {	// if v1 is GREATER THAN v2
			int temp = v1;	// temp <- v1
			v1 = v2;		// v1 <- v2
			v2 = temp;		// v2 <- temp
			out_of_order = true;
Last edited on
closed account (Dy7SLyTq)
while(true). its the same as while(out_of_order == true)
@DTSCode,

But is while(true) the same as while(out_of_order)?
If and only if out_of_order holds true...
Last edited on
closed account (Dy7SLyTq)
kind of. every loop condition and if branch test will only execute if it evaluates to true as out_order_does. if it was false you would have to make the condition !out_of_order or out_of_order == false
Thanks @kevinkjt2000,

But here's what confuses me. What does that mean for the whole while function? Does that mean the while statement runs until the out_of_order is false?
@DTSCode,

Thanks! That makes sense.

SO, the while function loops until the out_of_order variable is considered false. Once it is considered false, the next line of code executes?
closed account (Dy7SLyTq)
while isnt a function. its a loop. and all of the code between its start ({) and end (}) bracket execute until its false. then the next peice of code executes
@DTSCode,

Ok, last question:

Do the IF statements run at the same time?
closed account (Dy7SLyTq)
no.
Thanks!
Topic archived. No new replies allowed.