Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

How do you use the FOR <-- Loop in java !

OpenStudy (anonymous):

for(int i = 0; i <10; i++)

OpenStudy (anonymous):

you mean the trick? int i = 10; while (0 <-- i) { // Do stuff. }

OpenStudy (anonymous):

yea

OpenStudy (anonymous):

like for (int i=0; i<=something; i++); { }

OpenStudy (anonymous):

Shouldn't add a semicolon between the end of the for statement and the opening brace.

OpenStudy (anonymous):

yea , but like what does i++ mean

OpenStudy (anonymous):

each time it goes through loop i value is increased by 1 so you could write i = i + 1 or i+=1

OpenStudy (anonymous):

ohhhhhh ! ok

OpenStudy (anonymous):

thanks ! i hate comp science i dun even know why i took it ! LOL

OpenStudy (rsmith6559):

The ++ operator in C and C derived languages is the auto increment operator. -- is the auto decrement operator. If you have an int(eger) variable c, ++c would increment c before it is evaluated. c++ would evaluate the value of c and then increment it. They're actually called pre/post auto increment/decrement operators.

OpenStudy (anonymous):

what do you mean increment before it is evaluated

OpenStudy (rsmith6559):

{ int c = 9; printf( "%d\n", ++c ); /* will print 10 */ printf( "%d\n", c++); /* will print 10 */ printf( "%d\n", c ); /* will print 11 */ }

OpenStudy (anonymous):

also, something like i = ++i + i++ - --i - i-- would be undefined behavior :-P

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!