Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2007, 02:18 PM
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
Change my for loop
Code:
int a = 1; // a gets value from user int j=0; for(int i=a;i<10;i++) { // code goes here j = j++; if(j==10) break; }
I have the following piece of code. How can I alter for loop so that I can remove the while condition form my code.

Please advice.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007, 05:57 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
By while condition, I assume you mean the i < 10 part of your for loop. What are you trying to accomplish by getting rid of this?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 07:54 PM
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
I meant can we remove the if condition below and embed this in the for loop?
Code:
if(j==10) break;
Apologies for the confusion.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-11-2007, 08:11 PM
ShoeNinja's Avatar
Senior Member
 
Join Date: Oct 2007
Posts: 123
ShoeNinja is on a distinguished road
Send a message via AIM to ShoeNinja
Code:
for(int i=a;i<10 && j != 10;i++)
It seems like the above code will compile but I'm not sure if it will accomplish what you want. I've never thought about putting a complex condition there.

If all else fails, what you had in the first place is completely valid.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-12-2007, 01:00 PM
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
Perfect. It worked.
I wanted to know how to put two conditions in a for loop.

Thanks mate.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
do...while loop eva New To Java 16 01-31-2008 08:44 AM
while loop michcio New To Java 5 01-27-2008 02:56 AM
can you help me with this for loop? java_fun2007 New To Java 6 12-22-2007 12:20 PM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 10:44 AM
While loop leebee New To Java 1 07-18-2007 05:11 PM


All times are GMT +3. The time now is 04:24 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org