*
The moose likes Beginning Java and the fly likes Crazy Loops!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Crazy Loops!!" Watch "Crazy Loops!!" New topic
Author

Crazy Loops!!

Rupinder Bains
Ranch Hand

Joined: Jul 23, 2002
Posts: 65
Hi I am doing a Log book for uni, which keeps usual information of java to use throughout the next three years. I am just wondering how the following loops would be done.
To understand more.



Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
First, there are no loops in the code above - only conditionals.
Second, I don't understand your question . What excatly are your doubts about the code?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
I think the results of the three code segments are quite clear:
Segment one: the value won�t be printed out.
Segment two: the value won�t be printed out.
Segment three: the output should be twenty four.
My understanding to these three code segments is: Maybe they are illustrating some basic logic implementing with Java.
Martin Clifford
Greenhorn

Joined: Dec 02, 2002
Posts: 23
I believe the output of the first given example will by 21. This is becaue you want to output the value of VALUE if the value is greater than 30 (false), OR if it is less than 40 (true). Since one is true, then the expression evaluates to true, and the value will be printed.
The second given code will have no output, since MIN is set to the value of VALUE, it can't possibly be less than VALUE. There are no else statements, so nothing can be printed, and execution would simply continue past the entire block.
The last code example would produce 24 as it's output. Be careful with switch blocks, because if there had not been a BREAK statement after the increment in the 20's case, then the output would have been 26. The switch would have dropped through to the 40's case and added another 2 to the total.
Hope this helps some, and that it's not entirely incoherent )


Martin
Mellihoney Michael
Ranch Hand

Joined: Nov 27, 2002
Posts: 124
Martin's answer is perfect!
Don't think things too hard, but think them in different angels.
[ January 03, 2003: Message edited by: Melliholic Michael ]

a beginner in java
Robbie shi
Greenhorn

Joined: Jan 05, 2003
Posts: 28
first code :
result is 21
second code :
result is no_result
third code :
result is : 24
--
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
Divya Venkatesh
Greenhorn

Joined: Nov 05, 2002
Posts: 28
Can u please make your question more clear.
Regards :


Divya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Crazy Loops!!
 
Similar Threads
Nested if statements
Puzzled
Junit query
Help coding
StringTokenizer Class