• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with a while loop  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello please help with a while loop I can not understand how he felt at 0 value. The following code sample:
It outputs the result 00 11 21 32 42.

Thank you good luck.
-.png
[Thumbnail for -.png]
 
Bartender
Posts: 726
23
Eclipse IDE Hibernate jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags around you code so from next time please alway post code in code tags and quote your source. Refer Use Code Tags and Quote Your Sources

This is how It gets executed:
At beginning x = 0 and y = 0.
value of xvalue of yIs x < 5 ?y = x - yPrints x and yx = x + 1
000 < 5? = truey = 0 - 0 means y = 00 0x = 0 + 1 means x = 1
101 < 5? = truey = 1 - 0 means y = 11 1x = 1 + 1 means x = 2
212 < 5? = truey = 2 - 1 means y = 12 1x = 2 + 1 means x = 3
313 < 5? = truey = 3 - 1 means y = 23 2x = 3 + 1 means x = 4
424 < 5? = truey = 4 - 2 means y = 24 2x = 4 + 1 means x = 5
525 < 5? = false so control comes out of while loop---------
Output:
00
11
21
32
42
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!