• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

one more doubt regarding operators

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class test {
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do
while (i++ < 3)
System.out.print(k++);
while (j++ < 3);

}}
here inner while loop prints value of k as 0,1,2
this whole output should be repeated in outer do while loop until j++<3(four times)but how come result is only 012.sorry if i have misunderstood the concept
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lavanya sankuappan:
class test {
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do
while (i++ < 3)
System.out.print(k++);
while (j++ < 3);

}}
here inner while loop prints value of k as 0,1,2
this whole output should be repeated in outer do while loop until j++<3(four times)but how come result is only 012.sorry if i have misunderstood the concept



After you finish one iteration of the do-while loop, i++ is 3, so the inner while loop isn't entered again.
 
lavanya sankuappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that explanation keith
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lavanya,
I tried your code, Its compiling and running fine.
But I am not getting how it's working.
can u pls explain the loopings in this code...

Since there are no braces with do statement I am :roll: how this code will get execute...
Pls don't mind my querry as I am new to programmming..


Regards
swapnil
 
lavanya sankuappan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class test {
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do
while (i++ < 3)
System.out.print(k++);
while (j++ < 3);
}
}
the above question has a while-loop nested inside a do-loop.
 
Swapnil Trivedi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I got it....


Regards
Swapnil
 
straws are for suckers. tiny ads are for attractive people.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic