DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2005
    Posts
    115

    Simple for loop question

    Code:
    public class Test{
        public static void main(String[] args){
    	char[] list={'A','B','C','D','E','F','G','H','I','J'};
    	int city=5;
    
    	for(int i=0;(i<10&&i!=city);i++){
    		System.out.println(i);
    	}
    
    	}
    }
    I want print 0 to 10, excluding 5.

    But when i code it like this, it only prints up to 4 and exits the loop without printing 6 to 10.

    How should i code it?

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Code:
    for(int i=0;i<10;i++){
      if (i==city) continue;
      System.out.println(i);
    }
    It breaks the loop the way you coded it.
    eschew obfuscation

Similar Threads

  1. Very Simple Question - I think
    By Andrew Murphy in forum VB Classic
    Replies: 1
    Last Post: 09-03-2002, 01:17 AM
  2. Simple Java DOM question
    By Lenin in forum XML
    Replies: 0
    Last Post: 03-21-2001, 04:01 PM
  3. Simple Threading question
    By R in forum Java
    Replies: 0
    Last Post: 11-04-2000, 02:57 AM
  4. Simple Data Environment Question
    By Alex Nitulescu in forum VB Classic
    Replies: 1
    Last Post: 10-21-2000, 05:13 AM
  5. Simple Class Variables question
    By Gary McCallum in forum Java
    Replies: 2
    Last Post: 10-20-2000, 11:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links