+ 1

int i= 1;. for( ; i<=10; i = i++)

If we initialize the i in the declaration before the (for statement ) . Why we use semicolon in the initialize place in the for statement ?

12th Aug 2020, 3:46 PM
Himanshi Bisht
3 Antworten
+ 2
The semicolon is where it always is, just without another assignment. The syntax of the for loop doesn't change just due to another assignment.
12th Aug 2020, 3:56 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
its for loop syntax for(initial value; expression ; ++/--) The compiler see after first semicolon as expression, so there shd be two semicolons as it basic syntax.
12th Aug 2020, 4:04 PM
v@msi😉
v@msi😉 - avatar
+ 1
int a = 2; int b = a++; Here value of b is 2 and not 3 So, similarly int a = 2; a = a++; a has not increased! Instead you can try a++ or ++a or a = ++a all these methods will increment a
12th Aug 2020, 6:34 PM
Namit Jain
Namit Jain - avatar