Cann't we declare & initialize two variables in a for loop. for(int i=3,int j=5;i+j<20;i++,j++) //do something this code is giving me error while compiling. Can somebody explains this??? Thanx in advanced. --Shallender
robl
Greenhorn
Joined: Aug 26, 2000
Posts: 25
posted
0
You can initialize multiple variables in the init part of a for loop, but the corrct syntax is like this for( int i=0, j=0; i<10; i++, j++) {}
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
It means that we have to declare the varibale j before the starting of for loop otherwise it will give a complie error.
Praveen Zala
Ranch Hand
Joined: Jul 02, 2000
Posts: 118
posted
0
Hi there the code for(int i=3,int j=5;i+j<20;i++,j++) //do something will not compile alright !!! for(int i=3,j=5;i+j<20;i++,j++) //do something will compile !! But wonder why for(int i=3,char j=5;i<20;i++) //do something results in a compilation error ! ? Praveen Zala
Vijay T
Greenhorn
Joined: Sep 02, 2000
Posts: 5
posted
0
You need not declare 'j' before the beginning of for loop. The syntax
int i=0, j=0
will take care the declaration part for both i and j.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.