How to Create a Program in Mingw Developer Tool: The “While” Operator
Another presentation of another operator in Mingw tool. This time: the "while" operator.
The “while” operator is a cyclic operator inside Mingw which executes a series of operations as long as the condition inside brackets has the “True” value.
For example: If you want to add “+5″ to the “a” variable as long as “b” is a natural number you must use the “while” operator:
” While ( b > 0 ) a = a + 5; “
The only flaw of the “while” operator is that if you need to write some positive numbers on your screen, and one of them is “0″ and you use ” While ( x > 0 ) cout < < x; “, because of the initial testing in the “while” operator, “0″ will not pass the test. This is why the “while” operator has another form :
“Do… while”
The “Do…while” operator is a Mingw operator which has a final test, not an initial one, as “while” had. The only modification appears in its form:
” do
c = a + b;
while(a>0 && b>0); “
Note: After do you must not use “;”.
And also “&&” = and ; “||”=if; “!=” =different ; “%”= rest after division; “++” = +1; “–” =-1; “/10″=cuts the last digit from a number.
So, if you need to output how many digits a number has, you cannot use “while” because of:
“While (x != 0)
{digits++;
x=x/10;}” If the number is 0, it wont pass the test. So you must use:
“do
digits++;
x=x/10;
while(x!=0);
I hope you understood them both! Like or leave a comment if u need further explanation. Next time I will summarize the “for” operator.
Liked it










