For loops | SoloLearn: Learn to code for FREE!

+5

For loops

please, Is it possible to declare two variables in a for loop?........ e.g: for(int y = 3, d =5; y <= 10; d++)

7/1/2018 7:03:16 PM

Roff Bilex

21 Answers

New Answer

+40

yes you can declare two variables with for loop like this for(int i=0, j=5; i < 5; i++, j--) but take care condition part is not separated by seperator (,) for(int i=0, j=5; i < 5, j > 5; i++, j--)

+16

Yes, it is possible to instantiate two variables of the same type in the for loop declaration. But this example is an infinite loop, because you test the variable that isn't incremented. Just try it out at the code playground.

+4

Var x=0 For(;×<=20 x+=_) Document.write(×)

+3

yes,it is possible

+1

+1

yes excatly

+1

yea you can

+1

Declaring multiple variables in a single declaration could cause confusion about the types of variables and their initial values. In particular, do not declare any of the following in a single declaration: - Variables of different types - A mixture of initialized and uninitialized variables In general, you should declare each variable on its own line with an explanatory comment regarding its role. While not required for conformance with this guideline, this practice is also recommended in the Code Conventions for the Java Programming Language, §6.1, “Number Per Line” [Conventions 2009].

+1

yes you can and you can do another thing for example for(int i = 0 , j = n ; i < n ; --j , ++i) { }

+1

Yes it is possible like we declared variables by separating them like int a=3, b=4;

+1

Of course

+1

yes it is possible.

+1

Yes it is possible

+1

+1

what dose means sum =0

+1

Can someone help me to fill this_blank

+1

It is possible. It can be done with more than 2 variables. You could use 10 variables if you wanted to.

0

yes you can.

0

Как мне это решить!!!!!??????? >:(

0

Can someone plz explain this code to me in brief ??