For loop in new format

Hi
I am working on some project and am encountring for loop in some strange format. Can anyway help me with understanding this format of for loop.
this is something like:
for(Case q: cases)
can you simplify of map this to simple format of loop.
Thanks

This was introduced in JDK 1.5. Read the release notes for that to find out about this loop structure.
Basically it's a way to quickly loop, using iterators implicitly if the thing to the right of the colon is a Collection.

Similar Messages

  • How do I use For loop to check each node and import them to a new document?

    In my function I would like to use a For loop to get all the statutes (xml) inside the object
    objXmlBcaResponseDoc. In my case there are 2 statutes. I would like the output to look like the one I have posted here below. I am not sure how to do the For loop. The commented For loop is from another function but it is not working inside
    this function.
    The output is added into the **objXmlResponseMessageDoc** object and should look like this with 2 statutes (ns1:Statute) and a totalCount=2
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <StatutesXml>
    <Statutes runType="Request" runDateTime="2015-03-17T10:23:04" totalCount="2">
    <ns1:Statute xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </Statutes>
    </StatutesXml>
    </BasicSearchQueryResponse>
    My xml doc is found inside objXmlBcaResponseDoc Here is xml inside
    objXmlBcaResponseDoc object
    <BasicSearchQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/4.0">
    <ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/4.0">
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">8471</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">60</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">55</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    <ns1:Statute>
    <StatuteId xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">9722</StatuteId>
    <Chapter xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">90</Chapter>
    <Section xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0">25</Section>
    <Subdivision xsi:nil="true" xmlns="http://crimnet.state.mn.us/mnjustice/statute/4.0"/>
    </ns1:Statute>
    </BasicSearchQueryResponse>
    Here is my function
    Function GetStatutesByChapter(ByVal aobjXmlGetStatuteRequestNode As XmlNode, ByVal aobjXMLNameSpaceManager As XmlNamespaceManager, ByVal aobjBroker As ServiceCatalog.Library.v4.Broker) As XmlDocument
    Dim objXmlRequestMessageDoc As XmlDocument
    Dim objXmlResponseMessageDoc As XmlDocument
    Dim intCount As Integer
    aobjBroker.PostMessageWarehouseInformationalMessage("Chapter found.", 1)
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatuteByChapter with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("BasicSearchQueryResponse", "http://crimnet.state.mn.us/mnjustice/statute/service/4.0"))
    'Build the initial response document
    objXmlResponseMessageDoc = New XmlDocument
    'Add the first element into the document GetStatutesResponse with its namespace
    objXmlResponseMessageDoc.AppendChild(objXmlResponseMessageDoc.CreateElement("GetStatutesResponse", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Add a child node to the GetStatutesResponse node
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("StatutesXml", "http://www.courts.state.mn.us/StatuteService/1.0"))
    objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.CreateElement("Statutes", "http://www.courts.state.mn.us/StatuteService/1.0"))
    'Convert the node Statutes into an element and set the runType attribute (runType="Request") by adding it's value Request
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runType", "Request")
    'Convert the node Statutes into an element and set the attribute (runDateTime="2015-03-05T10:29:40") by adding it
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:GetStatutesResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("runDateTime", Format(Now, "yyyy-MM-ddTHH:mm:ss"))
    'Create the BCA request message
    objXmlRequestMessageDoc = New XmlDocument
    objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns1:BasicSearchCriteria", aobjXMLNameSpaceManager.LookupNamespace("ns1")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Chapter", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Section", aobjXMLNameSpaceManager.LookupNamespace("st")))
    objXmlRequestMessageDoc.SelectSingleNode("ns:BasicSearchQueryRequest/ns1:BasicSearchCriteria", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns2:Subdivision", aobjXMLNameSpaceManager.LookupNamespace("st")))
    'Uncomment last working section below
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Chapter", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Chapter", aobjXMLNameSpaceManager).InnerText
    'check if there is a section and or subdivision if it is there then set the value
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Section", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Section", aobjXMLNameSpaceManager).InnerText
    End If
    If Not (aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager) Is Nothing) Then
    objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns1:BasicSearchCriteria/st:Subdivision", aobjXMLNameSpaceManager).InnerText = aobjXmlGetStatuteRequestNode.SelectSingleNode("ss:Statute/ss:Subdivision", aobjXMLNameSpaceManager).InnerText
    End If
    'check if there is a section and or subdivision if it is there then set the value
    aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'Call the BCA service
    intCount = 0
    'This is where I want to use a For loop to check for the statutes found using the Chapter
    'Loop through each Id
    'For Each objXmlStatuteIdNode In aobjXmlGetStatuteRequestNode.SelectNodes("ss:Statute/ss:StatuteId/ss:Id[string-length(.)>0]", aobjXMLNameSpaceManager)
    'Create the BCA request message
    'objXmlRequestMessageDoc = New XmlDocument
    'objXmlRequestMessageDoc.AppendChild(objXmlRequestMessageDoc.CreateElement("ns:SingleStatuteRequest", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.SelectSingleNode("ns:SingleStatuteRequest", aobjXMLNameSpaceManager).AppendChild(objXmlRequestMessageDoc.CreateElement("ns:statuteId", aobjXMLNameSpaceManager.LookupNamespace("ns")))
    'objXmlRequestMessageDoc.DocumentElement.SelectSingleNode("ns:statuteId", aobjXMLNameSpaceManager).InnerText = objXmlStatuteIdNode.InnerText aobjBroker.PostMessageWarehouseSnapshot(objXmlRequestMessageDoc.OuterXml, "Request Message", 1)
    'intCount = intCount + 1
    'objXmlBcaResponseDoc = New XmlDocument
    'File name is BCASearchQueryResponse.xml
    'objXmlBcaResponseDoc.Load("\\j00000swebint\mscapps\deve\appfiles\temp\BCASearchQueryResponse.xml")
    'objXmlResponseMessageDoc.DocumentElement.SelectSingleNode("ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager).AppendChild(objXmlResponseMessageDoc.ImportNode(objXmlBcaResponseDoc.DocumentElement.SelectSingleNode("ns1:Statute", aobjXMLNameSpaceManager), True))
    'Next
    'Count how many Statute nodes found
    CType(objXmlResponseMessageDoc.SelectSingleNode("ss:BasicSearchQueryResponse/ss:StatutesXml/ss:Statutes", aobjXMLNameSpaceManager), System.Xml.XmlElement).SetAttribute("totalCount", CStr(intCount))
    Return objXmlResponseMessageDoc
    End Function

    What is XPath and what does it do that you're impressed with?
    Yes, I see your link, but give me the abbreviated elevator speech on what it is please. It has me curious.
    http://searchsoa.techtarget.com/definition/XPath
    http://www.techrepublic.com/article/easily-navigate-xml-with-vbnet-and-xpath/
    http://www.techrepublic.com/article/using-xpath-string-functions-in-xslt-templates/
    The way that all this is being used by me now on a project is the HTML controls on the screen are built by XML not only about what the controls are and their attributes,   but the data from from the database is XML too with both going through transfermations
    vis XSLT as the HTML controls are built dynamically by XML data for the controls and the XML database data with decision being made in the transfermation on the fly.
    There are many usages with Xpath not just this one I am talking about with Xpath. You can do the same kind of thing with XAML and WPF forms as they are dynamically built. But it goes well beyond what I am talking about and the usage of Xpath. Xpath 3.0
    is the latest version. 
    http://www.balisage.net/Proceedings/vol10/html/Novatchev01/BalisageVol10-Novatchev01.html
    Thanks - I'll look into that at some point.
    Still lost in code, just at a little higher level.

  • How can I have each pass through a for loop communicate with a new indicator?

    Hello,
    I am using 16 color boxes to indicate how 16 channels are behaving.  If a color box is blue, its respective channel is running correctly, red means it has failed etc.  I am continuously checking each channel using a loop, and I wanted to update the channel colors every loop.  I have made an array of 16 numbers corresponding to the color I wish to have (which are blue = running, red = failed, green = completed, black = not in use).  However, I cannot find a way to pull these 16 numbers out of the array and to the color boxes short of 16 index arrays connected to the color boxes. 
    I understand how to convert each individual number to a color, I just don't know how to use a 16 times for loop to communicate with a different color box each pass through.  Is there any way to do this or should I just go for brute force?
    Thank you.
    Solved!
    Go to Solution.

    Sorry I keep making new posts.  Attached is an example i wrote up.  There are three cases in the disabled structure, each has a different implementation of what i belive your specs are.
    Tim Elsey
    LabVIEW 2010, 2012
    Certified LabVIEW Architect
    Attachments:
    update color box.vi ‏24 KB

  • New Format for creating Attribute Sets.

    Hi,
    In SAP CRM webclient ui 7.0 there is a new format for creating Attribute Sets. The format is 'value table'.
    On selecting Format=Value Table the field 'Table' comes up.
    There is a message: Here you can enter a table that contains all the values you want to use. This is particularly useful for attributes with a lot of values or if you want to enter multiple attributes with the same values. The table must be a check table with a search help.
    Do I need to create a table with all the fields in in marketing attribute assignment block with search help on attributes field.
    Can you please guide as to how I should go about this issue.
    Regards,
    John.

    Hi John,
    The Attribute Set of Format type 'Value Table' is for the Mutiple Attribute Sets. These can be either a Single Attribute Set with Multiple values or the Multiple Attribute Sets with One value.
    You can include all such marketing attributes into one table which is a check table with search help. and use this as the Value Table.
    Hope this helps you out!
    Regards
    Veena.

  • How to get count from new enhanced for loop

    Is there a better way to determine the count when new enhanced for loop is used as follows:
    String[] test = new String[]{"1","2","3"};
    int count = 0;
    for(String i: test)
    count++;
    system.out.println("count: "+count);
    }

    There are cases where I need to use the count inside
    the for loop. I can keep track of the count by using
    the increment. But, then I would rather using the old
    for loop. Go ahead and use it. Are you under the assumption that the old form should be avoided?
    There is no saving in term of efficiency and readability.If there is any added efficiency in the "for each" form of the loop, it is on the micro level, and you would never notice it.
    As far as readability, look at some of the crazy solutions you've been given to avoid the general for loop, then reconsider which is more readable.

  • My ipod is formated for windows xp. new laptop is windows 8. ipod wont update on new laptop, what do i do now?

    my new laptop is windows 8. iPod is formatted for windows xp. new laptop knows iPod is there but wont update. how do I fix this?

    hey there oddball35,
    It sounds like you are trying to update your iPod with your new computer. Without knowing the specific symptoms, I recommend you start with choosing the iPod model you have from the following website:
    iPod Troubleshooting Assistants
    https://www.apple.com/support/ipod/five_rs/
    If that does not resolve the issue, are you getting any error messages, or what specifically is preventing the restore from happening?
    Thank you for using Apple Support Communities.
    All the best,
    Sterling

  • Removing Items While Using New For Loop

    Consider this:
    ArrayList<String> a = new ArrayList<String>();
    ... add some stuff ...
    for(String s : a) {
    // Do some stuff
    if(some_condition) {
    a.remove(s);
    This will cause a ConcurentModificationException the a.remove(s) is ever run. Is there anyway to call the iterator.remove() method instead? The new syntax is much cleaner, and I'd like to use it, but I need to be able to call iterator.remove()
    Anyone?

    I think the code should iterate through a, putting
    references to objects in an auxillary array and then
    the loop will go through the auxilary array rather
    than the original data structure. This perfectly
    reasonable, but different implementation results in
    drastically different results (the example above would
    work fine). I see this as an issue of these general
    language features being defined to close to the metal.
    Their semantics are defined by their implementation
    not by a sound language design decision that is
    agnostic to different implementations.The enhanced for loop is defined in terms of java.lang.Iterable, a very simple interface, which can be implemented in many different ways. You can't get much farther from the metal. The concurrent modification exception is a feature of particular implementations of that interface. If you don't like those implementations, use others that behave differently. For example, you could use one of the CopyOnWrite collections implementations in java.util.concurrent, which never throw a concurrent modification exception. Your suggestion to copy the elements into an array is one (inefficient) implementation mechanism for such collections.

  • Downloaded new format yesterday and now when playing music the sound is low for first few seconds of each subsequent track. Is this a bug?

    Under new format when playing music each track after the first starts in low volume then kicks in within 3 seconds. very irritating. is this a bug?

    I'm having the same issue on my iPad (the "new iPad" / 3rd gen with retina display and 30 pin dock connector) after downloading iOS 7 (is that what you meant by the new format, updating to iOS 7?).
    The music will play quietly for a few seconds then it will play at the volume it's supposed to.

  • For loop format

    Ok so everybody knows the standard for loop format of:
    for (initialization; termination; increment)
    but what does it mean when you add a 4th expression to the mix?
    this is from the Java Tutorial 4th Edition pg. 250
    for (int i = 0; n = elements.length; i < n; i++)
    Can somebody explain this please?

    Perhaps you're thinking of something like this?
    for (int ix = 0, jx = 10; ix < 100; ix++,
    jx++)
    ok good - well what does this mean?oh wait - this just means initialize 2 things before starting the loop, right? I get it now.

  • HT1689 with the new format I don't see where I download updates for the apps.  My phone says I need 18 updates on my apps and I can't find where to do this in the new format. Help.

    Thank you anyone for the help.

    The new format of what?
    If you're running iOS 6 and want to dowonload updates directly to your iPhone,  you can open the App Store and click "Updates" in the lower right and install them from there.
    If you're talking about iTunes 11 on your computer, then switch to the Apps button on the upper left and you can download them from there.

  • What happened to my regular format for my Fox News app? It automatically went to Mobile format.

    What happened to my regular Fox News app? It automatically went to Mobile format.

    Thought  I would update my question. I heard back from Fox News by email.  this is what they said..."Hi,
    Thank you for taking the time to report this issue.  There was an issue with Foxnews.com this morning that left some users unable to access the full website from phones or tablets.  We apologize for any inconvenience and you should now be able to access our full site.
    From tablets: enter www.foxnews.com in your browser
    From phones: enter www.foxnews.mobi and click the “View Full Site” near the bottom of the page
    If you continue to see errors with the mobile site or website, please do not hesitate to reach out. We appreciate your patience and hope you continue to turn to Fox News for all your news!
    Thanks,
    The Fox News Mobile Team"

  • Gmail desktop new format comes up in Firefox as Android format, unreadable on desktop computer. Why? Changed to Safari for readable Gmail.

    I have used Firefox for many years for my Gmail account. The system changed over yesterday afternoon, and does not provide an option to change back to old format. Format is VERY tiny and completely unreadable. There is not obvious setting feature to change this. i was forced to open a new Safari browser in order to use my Gmail account, as it is not usable in the new format in Firefox.

    hello cmbryan, try to press ctrl+0 ('zero') while you're on the page in order to reset the zoom level or in case this doesn't work also [[Clear the cache - Delete temporary Internet files to fix common website issues|clear the cache]] & [[Delete cookies to remove the information websites have stored on your computer|cookies from google.com]] and reload the page.
    [[Websites look wrong or appear differently than they should]]

  • NEW FORMAT FOR DISCUSSIONS

    does anyone else wish that apple would stop reinventing the wheel and leave a good thing alone?
    i used to solve every problem thru the great posts on this site. now i cant find anything.
    this new format is the most user unfriendly i have ever experienced. if i have to scroll through one more interminable lists of iphone or itunes topic i am going to scream.
    i feel like it's catering to kids now. going to start using macforum or other sites until applegets it together...anyone have this experience? maybe they'll listen to a bunch of us.

    amy
    Why not narrow the search?
    Click on the 'More Options links and you can refine the search to a specific forum, specific, specific poster even.
    Regards
    TD

  • For Loop and Void Method Questions

    Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted.
    Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)?
    Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now.
    for (int index = 0; index < howNum; index++) // process each number in the array
              enterYourNumbers = JOptionPane.showInputDialog   
                            ("Enter a number between 1 and 100");                       
              numArray = new double[howNum]; 
            try
                numArray[index] = Double.parseDouble(enterYourNumbers);
            catch (NumberFormatException e)
                    enterYourNumbers = JOptionPane.showInputDialog
                              ("Enter a number between 1 and 100");                          
                DecimalFormat fmt = new DecimalFormat ("###,###.00");
                JOptionPane.showMessageDialog(null, enterYourNumbers + " "  + "squared is "  + fmt.format(calcSquare(numArray[index]))
                                              + "\n" + enterYourNumbers + " " +  "cubed is " + fmt.format(calcCube(numArray[index])));                                                                           
                wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
      while (wantToContinue.equalsIgnoreCase("y"));
    import javax.swing.*;
    import java.text.DecimalFormat;
    public class Array
        public static void main(String[] args)
            int howNum = 0;
            int whichNum = 0;     
            double[] numArray;
            boolean invalidInput = true;
            String howManyNumbers, enterYourNumbers, wantToContinue;
      do // repeat program while "y"
          do // repeat if invalid input
            howManyNumbers = JOptionPane.showInputDialog
                        ("How many numbers do you want to enter");                     
            try
                 howNum = Integer.parseInt(howManyNumbers);
                 invalidInput =  false;
            catch (NumberFormatException e )
                howManyNumbers = JOptionPane.showInputDialog
                            ("How many numbers do you want to enter");
          while (invalidInput);
          for (int index = 0; index < howNum; index++) // process each number in the array
              enterYourNumbers = JOptionPane.showInputDialog   
                            ("Enter a number between 1 and 100");                       
              numArray = new double[howNum]; 
            try
                numArray[index] = Double.parseDouble(enterYourNumbers);
            catch (NumberFormatException e)
                    enterYourNumbers = JOptionPane.showInputDialog
                              ("Enter a number between 1 and 100");                          
                DecimalFormat fmt = new DecimalFormat ("###,###.00");
                JOptionPane.showMessageDialog(null, enterYourNumbers + " "  + "squared is "  + fmt.format(calcSquare(numArray[index]))
                                              + "\n" + enterYourNumbers + " " +  "cubed is " + fmt.format(calcCube(numArray[index])));                                                                           
                wantToContinue = JOptionPane.showInputDialog ("Do you want to continue(y/n)? ");
      while (wantToContinue.equalsIgnoreCase("y"));
        public static double calcSquare(double yourNumberSquared)
            return yourNumberSquared * yourNumberSquared;       
        public static double calcCube(double yourNumberCubed)
           return yourNumberCubed * yourNumberCubed * yourNumberCubed;              
        public static void calcAverage(double yourNumberAverage)
    }

    DeafBox wrote:
    Question 1: How would I write a for loop that repeats the according to the number entered, to prompt the user to enter a number (double) between 1 and 100. If the number is outside this range it is not accepted. Use a while loop instead.
    Question: 2 Also how would I write a for loop to do sum and find the average of the array numbers in a seperate void method( does not return anything to the main method)? Why would you want to use 2 methods. Use the loop to sum the numbers. Then after the loop a single line of code calculates the average.
    Question: 3 (first code snippet) With my for loop that is used to process each number in the array and square it and cube it and display the results to 2 decimal places. How do I make it so say I want the array to allow me to enter 2 numbers (so I enter 2 numbers) then it asks me to enter a number between 1 -100 (which will prompt 2 times) that it shows me the results for the entered numbers between 1-100 after one another instead of number then result number then result like I how it now. If I understand you correctly, use 2 loops. One gathers user inputs and stores them in an array/List. The second loop iterates over the array/List and does calculations.

  • For Loop Will Not Execute

    I have been a software engineer for a number of years now, and thus far I have never come across any coding issues that truly merit a post such as this. Someone has almost always run across the issue before, so there is no need to reinvent the wheel, or solution as it were.
    However, a number of times I have run across instances where the JRE simply... does not execute parts of my code, and throws no exceptions.
    The sample code is a simple logging application, watered down to the bare minimum for the purposes of this forum:
    public class Log {
    public static void main(String[] args)    {Log log = new Log();}
    public Log() {Logger.log("Hello World");}
    import java.util.*;*
    import java.io.*;
    import java.text.SimpleDateFormat;
    public abstract class Logger {
    private static final int SIZE = 2;
    private static final SimpleDateFormat DAY = new SimpleDateFormat("EEEE");
    private static final String
      DIR = "logs/",
      EXT = ".log",
      FILTER = ".*log\\z",
      DNE = "DNE";
    private static int i,oldest;
    private static long previous = 0;
    private static FileFilter filter = new LogFilter();
    private static FileWriter out;
    private static File file,directory;
    private static File[] list;
    public synchronized static void log(String param) {
      try {
       directory = new File(DIR);
       file = new File(DIR + getDay() + EXT);
       list = directory.listFiles(filter);
       if (file.createNewFile()) {
        readOnly();
        reconcile();
       write(param);
      catch (Exception exception) {}
    private static void write(String param) throws Exception {
      out = new FileWriter(file, true);
      out.write(param);
      out.close();
    private static void readOnly() throws Exception {
      for (i=0;i<list.length;i++) {list.setReadOnly();}
    private static void reconcile() {
    try {
    previous = list[SIZE].lastModified();
    oldest = SIZE;
    for (i=SIZE;i<=0;i--) {
    if (list[i].lastModified() <= previous) {
    previous = list[i].lastModified();
    oldest = i;
    list[oldest].delete();
    catch (Exception exception) {System.out.println("Skipping reconciliation...");}
    private static String getDay() throws Exception {
    return DAY.format(Calendar.getInstance().getTime());
    private static class LogFilter implements FileFilter {
    public LogFilter() {}
    public boolean accept(File param) {
    try {
    if ((param.getName()).matches(FILTER)) {return true;}
    else {return false;}
    catch (Exception exception) {return false;}
    *The problem*:
    Ok, easy visual, this is the "log/" directory as I run the Log.java application repeatedly and iterate the date on my computer as I do so.
    Thursday
    *log/*
    +Thursday.log+
    Friday
    *log/*
    +Thursday.log+
    +Friday.log+
    Saturday
    *log/*
    +Thursday.log+
    +Friday.log+
    +Saturday.log+
    Sunday
    *log/*
    +Friday.log+
    +Saturday.log+
    +Sunday.log+
    Monday
    *log/*
    +Friday.log+
    +Saturday.log+
    +Monday.log+
    This is the point at which I go ???
    Turns out, the JRE skips the execution of my for loop in the *reconcile()* method when the date rolls over to Monday, and from then on it simply deletes the previous day's log instead of the oldest log.
    Why?  Who knows.
    Things I have tried:
    - Using another variable integer for the *readOnly()* method
    - Removing the synchronized keyword from the *log(String param)* method
    - Second call to *directory.listFiles(filter)* and setting *SIZE* to *3* after the old files have been set to read-only
    - Removing the call to *readOnly()*
    - Verified that the call to *readOnly()* does not alter the +modified+ date on the log files
    - Changed Logger.java from a +static+ class to a +local+ class
    Things I cannot do:
    This log application stores privy information about end-users at locations across the country in the event that there are support issues that need to be resolved, and the agreement is that we store this information no more than three days.  Just wanted to make sure, that the hopefully informed respondants to this issue, know that the obvious solution (storing seven day records), is unfortunately not available to me.
    Edited by: Threadstorm on Jan 8, 2009 8:24 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    HA! Most excellent. The last place I would ever look.
    Yes, seems like Java sorts the files in such a way that everything works fine without the loop until Monday rolls over.
    Now I can have a better appreciation for that second set of eyes.
    I use for loops so frequently that I never look at them (though I did stare at this one myself prior to this post, much to my chagrin now) but the subtracting iteration (which I use once in a blue moon) was necessary for the nature of the code.
    But ok, up and running! (whew) was going to be a long day until now.
    To answer your question though, the Logger is static so I don't have to pass it around to dozens and dozens of other modules but rather just include the package on the fly as I develop new modules that need to log information, and I like to write most mundane things myself if I can, that way I have the freedom to modify them at will.
    Thanks again! I'm now a happy camper once more.
    I'm also thankful that I don't have to chalk up another notch on the wall of cases where the JRE behaves magically and truly ignores code which I have definitely run into before. Something about listCellRenderers and the order of calls made to them, or some such and JRE doesn't read one of the lines. It's been a year or two.
    Edited by: Threadstorm on Jan 8, 2009 8:47 AM

Maybe you are looking for