+ 6
Why x-- ;
9 Antworten
+ 7
It means 'x = (x - 1);'
+ 7
int x = 15;
while( x > 0 ) {
System.out.println("Our x is : " + x );
x--;
}
/*
Our output will be
Our x is : 15
Our x is : 14
Our x is : 13
.
.
.
Our x is : 2
Our x is : 1 // here, when it will try to decrement x again, that while loop will exit because while( 0 > 0 ) is not true.
*/
+ 3
With pleasure
+ 2
ookkkaay
thanks a lot
+ 2
when you write x-- ,
the value of x will decrement as x=x-1 but the change will be "after" that line executed...
same as when you write --x,
the value of x will decrement as x=x-1 but the change will be "within" that line executed...
+ 1
if you don't give decrement/increment statement for a variable in while loop for which you are running a loop as...
while ("condition of x")
the value of x will remain same and unchanged for next loop operation and the condition will again true for next operation and thus it will go in an infinite loop which cause to terminate program in unexpected manner
0
I know that
but
while (){
......
.....
x-- ;
}
????
0
x- = x=x-1
0
ربحتك 2 😋