Why x-- ; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6
18th Dec 2016, 12:13 PM
Keriou Lamis
Keriou Lamis - avatar
9 Answers
+ 7
It means 'x = (x - 1);'
18th Dec 2016, 12:40 PM
Javier Calvo
Javier Calvo - avatar
+ 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. */
18th Dec 2016, 1:06 PM
Adrian Gheorghe
Adrian Gheorghe - avatar
+ 3
With pleasure
18th Dec 2016, 1:09 PM
Adrian Gheorghe
Adrian Gheorghe - avatar
+ 2
ookkkaay thanks a lot
18th Dec 2016, 1:07 PM
Keriou Lamis
Keriou Lamis - avatar
+ 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...
19th Dec 2016, 11:16 PM
MAULIK SONI
MAULIK SONI - avatar
+ 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
19th Dec 2016, 11:22 PM
MAULIK SONI
MAULIK SONI - avatar
0
I know that but while (){ ...... ..... x-- ; } ????
18th Dec 2016, 12:48 PM
Keriou Lamis
Keriou Lamis - avatar
0
x- = x=x-1
16th Mar 2017, 5:20 PM
DAHMANI MOHAMED ELAMINE
DAHMANI MOHAMED ELAMINE - avatar
0
ربحتك 2 😋
16th Mar 2017, 5:20 PM
DAHMANI MOHAMED ELAMINE
DAHMANI MOHAMED ELAMINE - avatar