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...):
#include <iostream>
usingnamespace 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;
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
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?
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