• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

for loop with two variables ...

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

int i =0;
int j =0;
for (i=0, j=0; ..... )
//is valid.
BUT
if i say
int j;
for(int i =0, j=0; ....)
//is invalid WHY ? WE HAVE DECLARED J ONLY ONCE !!!
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't mix your style of declaration. Same as typing your declarations on one line, you either declare them all on one line with the int at the beginning, or you declare them all on separate lines.
You can say:
int i=0, j=3, k=9;
but you can't say:
int i=0, int j=3, int k=9;
or:
int i;
i=0, int j=3;
Bill
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the line
for (int i=0, j=0;...;...)
is the same as saying :
define i as an integer and set it to 0
AND
define j as an integer and set it to 0
but you have already done that with j, thus error!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic