• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have do while loop query ?  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the code ....


I get the outcome as 2

I get the outcome as 1 .

How is this possible ?  what's the difference between the two ?
 
author
Sheriff
Posts: 23329
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Vijairam Ganeshmoorthy wrote:
How is this possible ?  what's the difference between the two ?



This question has nothing to do with the loop. The difference is in the post increment operator... and how the increment is applied after the variable (increment) has been evaluated.

... or in other words... while the variable is incremented, the value of the expression "i++" is the value of the variable before the increment.

Henry
 
Sheriff
Posts: 11626
187
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To Henry's point, that code will behave exactly the same way without the do while loop around it.
 
BWA HA HA HA HA HA HA! Tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!