Home arrow static arrow Java Programming [Archive] - How can I tell to my program...
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - How can I tell to my program...
This topic has 12 replies on 1 page.

Posts:114
Registered: 7/5/04
How can I tell to my program...  
Aug 4, 2004 8:44 PM



 
Hi

How can I tell to my program:

public void method()    do something    If(ok){       Return to execute the method or the Do    }Else{      Do something else    } }


thanks
D
 

Posts:152
Registered: 7/11/03
Re: How can I tell to my program...  
Aug 4, 2004 8:48 PM (reply 1 of 12)



 
not sure if your just looking for the basics but:

public void methodName(int num)
{
System.out.println("My program works");
if(num==1)
{
System.out.println("One");
}
else
{
System.out.println("Not One");
}
}
 

Posts:114
Registered: 7/5/04
Re: How can I tell to my program...  
Aug 4, 2004 8:50 PM (reply 2 of 12)



 
not at all...

do a thing,if one condition is materialized go back and do a again until the conidion is false,than do another things...
 

Posts:2,830
Registered: 9/1/03
Re: How can I tell to my program...  
Aug 4, 2004 8:52 PM (reply 3 of 12)



 
while(true){  System.out.println("do it.");  if(something){     break;  }}System.out.println("do other stuff.");
 

Posts:152
Registered: 7/11/03
Re: How can I tell to my program...  
Aug 4, 2004 8:54 PM (reply 4 of 12)



 
oh a loop

public void countTrial()
{
for(int count =0; count < 10; count++)
{
if(count < 5)
{
System.out.println(count+"");
}
else
{
System.out.println("Print this 5 times");
}
}
}
 

Posts:114
Registered: 7/5/04
Re: How can I tell to my program...  
Aug 4, 2004 9:09 PM (reply 5 of 12)



 
while(true){System.out.println("do it.");if(something){break;}}System.out.println("do other stuff.");

Thanks dud!

if the "while" is inside "for", the break will break the for as well?
 

Posts:2,830
Registered: 9/1/03
Re: How can I tell to my program...  
Aug 4, 2004 9:13 PM (reply 6 of 12)



 
while(true){System.out.println("do it.");if(something){break;}}System.out.println("do other stuff.");

Thanks dud!

if the "while" is inside "for", the break will break
the for as well?

no, break will only break the first loop, you can use a labelled break in
that case, i believe.
 

Posts:56
Registered: 5/16/03
Re: How can I tell to my program...  
Aug 4, 2004 9:17 PM (reply 7 of 12)



 

if the "while" is inside "for", the break will break
the for as well?

Nope...U have to define a label for the outer loop and break to that label...
 

Posts:114
Registered: 7/5/04
Re: How can I tell to my program...  
Aug 4, 2004 9:32 PM (reply 8 of 12)



 
thanks guys u helped me a lot
 

Posts:37,103
Registered: 3/30/99
Re: How can I tell to my program...  
Aug 4, 2004 9:58 PM (reply 9 of 12)



 
if the "while" is inside "for", the break will break
the for as well?

You could write some code to test what happens. When you have questions like "How do I ...?" it's fine to ask here, but when your question is "What will this code do?" you'll really be better served if you just play around with that code and variations on it to see firsthand what happens.

Also, you may want to check out the following:

[url=http://java.sun.com/docs/books/tutorial/]Sun's basic Java tutorial[/url]

[url=http://java.sun.com/learning/new2java/index.html]Sun's New To Java Center[/url]. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.

[url=http://javaalmanac.com]http://javaalmanac.com[/url]. A couple dozen code examples that supplement [url=http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance]The Java Developers Almanac[/url].

[url=http://www.jguru.com]jGuru[/url]. A general Java resource site. Includes FAQs, forums, courses, more.

[url=http://www.javaranch.com]JavaRanch[/url]. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.

Bruce Eckel's [url=http://mindview.net/Books/DownloadSites]Thinking in Java[/url] (Available online.)
Joshua Bloch's [url=http://www.amazon.co.uk/exec/obidos/Author=Bloch,%20Josh]Effective Java[/url]
Bert Bates and Kathy Sierra's [url=http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance]Head First Java[/url].
 

Posts:5,965
Registered: 5/17/03
Re: How can I tell to my program...  
Aug 4, 2004 10:00 PM (reply 10 of 12)



 
I don't fully get your logic but can't you just do this,
do {   // do something} while ok;// do something else
 

Posts:110
Registered: 3/10/04
Re: How can I tell to my program...  
Aug 4, 2004 10:38 PM (reply 11 of 12)



 
Hi,

There’s no goto in Java. The one unconditional jump mechanism is the break label or continue label, which is used to jump out of the middle of multiply-nested loops.

test: for (int i = fromIndex; i + max1 <= max2; i++)
{
if (charAt(i) == c0)
{
for (int k = 1; k<max1; k++)
{
if (charAt(i+k) != str.charAt(k))
{ continue test;
}
}

}/* end of inner for loop */
} /* end of outer for loop */


 

Posts:2,909
Registered: 13.8.2003
Re: How can I tell to my program...  
Aug 4, 2004 11:10 PM (reply 12 of 12)



 
I don't fully get your logic but can't you just do
this,
do {// do something} while ok;// do something else

Thank you uj, I thought I'd have to make that post.
 
This topic has 12 replies on 1 page.