For loop: all conditions : For « Language Basics « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Language Basics » For 




For loop: all conditions
 
/*
 *     file: ForLoops.java
 *  package: java2s.hcj.review
 *
 * This software is granted under the terms of the Common Public License,
 * CPL, which may be found at the following URL:
 * http://www-124.ibm.com/developerworks/oss/CPLv1.0.htm
 *
 * Copyright(c) 2003-2005 by the authors indicated in the @author tags.
 * All Rights are Reserved by the various authors.
 *
 ########## DO NOT EDIT ABOVE THIS LINE ########## */

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

/**
 * Syntax check file for for loops.
 
 @author <a href="mailto:[email protected]">Robert (Kraythe) Simmons jr.</a>
 */
public class ForLoops {
  /**
   * A wordy for loop.
   */
  public static void forLong() {
    Properties props = System.getProperties();
    Iterator iter = props.keySet().iterator();

    String key = null;
    while (iter.hasNext()) {
      key = key = (Stringiter.next();
      System.out.println(key + "=" + System.getProperty(key));
    }
  }

  /**
   * A completely safe and short for loop.
   */
  public static void forSafe() {
    Properties props = System.getProperties();
    Iterator iter = props.keySet().iterator();
    for (String key = null; iter.hasNext(); key = (Stringiter.next()) {
      System.out.println(key + "=" + System.getProperty(key));
    }
  }

  /**
   * A short for loop.
   */
  public static void forShort() {
    Properties props = System.getProperties();
    for (Iterator iter = props.keySet().iterator(); iter.hasNext();) {
      String key = (Stringiter.next();
      System.out.println(key + "=" + System.getProperty(key));
    }
  }

  /**
   * A simple for loop.
   
   @param args
   *          Arguments to the loop.
   */
  public static void forSimple(final String[] args) {
    for (int idx = 0; idx < args.length; idx++) {
      // .. do something.
    }
  }

  /**
   * A weird for loop.
   */
  public static void forWeird() {
    boolean exit = false;
    int idx = 0;

    for (System.setProperty("user.sanity""minimal"); exit == false; System.out.println(System
        .currentTimeMillis())) {
      // do some code.
      idx++;
      if (idx == 10) {
        exit = true;
      }
    }
  }

  /**
   * Demo method.
   
   @param args
   *          Command line args.
   */
  public static void main(String[] args) {
    forWeird();
  }

  /**
   * A for loop bug.
   
   @param customKeys
   *          __UNDOCUMENTED__
   */
  public static void propsDump(final Set customKeys) {
    Properties props = System.getProperties();
    Iterator iter = props.keySet().iterator();

    String key = null;
    System.out.println("All Properties:");
    while (iter.hasNext()) {
      key = (Stringiter.next();
      System.out.println(key + "=" + System.getProperty(key));
    }

    System.out.println("Custom Properties:");
    iter = customKeys.iterator();
    while (iter.hasNext()) {
      System.out.println(key + "=" + System.getProperty(key));
    }
  }
}

/* ########## End of File ########## */

           
         
  














Related examples in the same category
1.for Demofor Demo
2.Check out for loopCheck out for loop
3.Java labeled for loop.Java labeled for loop.
4.Demonstrates for loop by listing all the lowercase ASCII letters.Demonstrates for loop by listing all the lowercase ASCII letters.
5.Comma OperatorComma Operator
6.Declare multiple variables in for loop
7.Infinite For loop Example
8.Multiple expressions in for loops
9.Java program to demonstrate looping 1Java program to demonstrate looping 1
10.Java program to demonstrate loopingJava program to demonstrate looping
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.