aspose file tools*
The moose likes Beginning Java and the fly likes Loops question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loops question" Watch "Loops question" New topic
Author

Loops question

Rob M Jones
Greenhorn

Joined: Nov 16, 2011
Posts: 2
Hi everyone, I am currently studying java and came across this question on one of the practice exams. I have stepped through each iteration of the loops but am stumped as to why x is never increased to 4 when i is set to 1. Can anyone shed some light on this?
Thanks!



By the way the output is --,<
amro talaat
Greenhorn

Joined: Sep 02, 2012
Posts: 4
Rob M Jones wrote:Hi everyone, I am currently studying java and came across this question on one of the practice exams. I have stepped through each iteration of the loops but am stumped as to why x is never increased to 4 when i is set to 1. Can anyone shed some light on this?
Thanks!



By the way the output is --,<


try if else ???
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 242

Rob M Jones wrote:Hi everyone, I am currently studying java and came across this question on one of the practice exams. I have stepped through each iteration of the loops but am stumped as to why x is never increased to 4 when i is set to 1. Can anyone shed some light on this?
Thanks!



By the way the output is --,<


Try


Sent from my IBM 360 mainframe
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Check this FAQ.


[My Blog]
All roads lead to JavaRanch
Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

why x is never increased to 4 when i is set to 1.


you can see that you have assigned the value of post increment x to x i.e x=x++
so x is assigned a value before it is incremented
you can try x = ++x
or simply x++ or ++x

hope it helps


Ankit
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
The idea of that question may be to find out whether you can see
i = i++;
and realise there is a trap for the unwary!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loops question