While loop c++

I saw some people use

while(t–)

in their code when I was looking at others’ solutions. How do you use a while loop without a comparison operator?

By default , while loop runs till the expression inside it is true or greater than zero. So , while(t–) runs till the value of t is greater than zero.

1 Like

Does the while loop check the value of t before or after 1 is subtracted from it? The expression inside is t-1 which would let the while loop run t-1 times, but I would assume the loop is supposed to run t times.

Lets just say that

while(expression)
{
     //some code
}

works till the expression is true.

So consider that every value other that “0” is true. So it works till the integer is true.

The link will help you quickly. just go through it once.

Link : http://ideone.com/MtM4cl

1 Like

t-- means it will first take the current value of t in the expression and then decrease its value in the next step…So, suppose t=3 , while(t–) means that it takes it as while(3) and entering in the while loop and decreasing t are simultaneous action.