Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Programmer Certification (OCPJP)
Can you expailn me the flow..
Anish Nagraj
Greenhorn
Posts: 20
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public class primitives {
public static void main(
String
[]args) {
int x = 0;
labelA :
for(int i =10; i<0; i--){
int j=0;
labelB:
while(j<10){
if(j>i) break labelB;
if(i==j){
x++;
continue labelA;
}
j++;
}
x--;
}
System.out.println(x);
}
}
This program gives me output as 0
I am not able tp know the flow... plz help
Chris Allen
Ranch Hand
Posts: 127
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It is because of your for loop condition. You are initializing i=10 and then checking to see if i<0. None of the code inside the for loop is executed which leaves the value of x=0.
If you're gonna buy things, buy this thing and I get a fat kickback:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
loop
why output is 0 ?
Flow Control
Applet - Graphing Quadratic Function Help
Cannot understand the flow of code...
More...