• 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

Control Flow (for loop)

 
Ranch Hand
Posts: 104
Netbeans IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why this declaration cause compile exception
int j=10;
for(int i-10 ,j+=90;i<j;i++){
j--;
}
And is there any diffrence between below two statement?
1.for(int i=0,j=100;i<j;i++,--j){;}
2.for(int i=0,j=100;i<j;i++,--j){}
when i run this code then both code run but i cannt any diffrence between it?
thank you
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

j+=90



You are mixing assignments + declarations + An arithmetic operation. Not allowed. j=90 would work



The extra semicolon is as good as no statements in the for loop. A semicolon is supposed to end a line of code. Your line of code is empty. So it is as good as no code.>
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinit sharma wrote:why this declaration cause compile exception
int j=10;
for(int i-10 ,j+=90;i<j;i++){
j--;
}


look this int i-10 ?

vinit sharma wrote:
And is there any diffrence between below two statement?
1.for(int i=0,j=100;i<j;i++,--j){;}
2.for(int i=0,j=100;i<j;i++,--j){}


i dont find any difference expect ";" which has no effort here
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, please post your code in CODE tags. It will easier for people to read your post. You will attract more replies that way
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahh.. Deepak Bala is faster than me
 
appu sharma
Ranch Hand
Posts: 104
Netbeans IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Deepak
Thank you for your time but j=90 would also not work,i tested it too
@seetharaman venkatasamy
thank you for your suggestion next time i should care to write code in CODE tags
can you further explain clearly my question because i cannt get proper answer??
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It will work if you have not defined j previously.

Let us know what part of the explanation was inadequate. We can elaborate>
 
appu sharma
Ranch Hand
Posts: 104
Netbeans IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you deepak
 
reply
    Bookmark Topic Watch Topic
  • New Topic