Help with...for loops

Can anyone explain to me how I follow what this loop is doing by using a trace table (I know We've covered it but I can't find it in my notes)
int n = 5
int sum = 0
for (int i = 0; i < n + 1; i + i)
sum = sum + i
any help would br GRATEFULLY appreciated!

its an infinite loop.if u want infinite loop dont bother declaring veriables just type for(;;)
:P

Similar Messages

  • Help with for loop and remove-item command

    Hi all here is the code so far
    $a = Get-Content C:\Users\cody-horton\Desktop\test.txt
    for($i=0;$i -lt $a.Length;$i++){
    #$temp = [int32]::Parse($a[$i])
    Remove-Item '\\ceit2551202x0'$a[$i]'\C$\Program Files\MATLAB\R2013a\*' -Force
    I have a text file with a few number in it that i want to get. They are in the array $a but I'm getting an error that says a positional parameter cannot be found that accepts argument '53' (it does this for all the numbers in the array.) I know in java you
    could have something like this   string + int + string. 
    I'm not sure what to do I also tried to parse it with no luck. Thanks any help is appreciated.

    Your issue is with the path for Remove-Item, it is not complete so try this
    Remove-Item "\\ceit2551202x0$($a[$i])\C$\Program Files\MATLAB\R2013a\*" -Force
    I am unable to test, so I would add the -WhatIf switch to make sure it outputs what you expect
    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.
    Don't Retire Technet

  • Help on changing array elements with For loop

    Hi,
    I'm wondering if anyone can help me with this problem.  I'd like to be able to modify elements of an array with For loop.  In the attached VI, my goal is to have an array of [0 1 2 3 4 5], but instead what I've got is [2 2 2 2 4 5].  I initialized the array with a value of 2 to help me identify which elements are changing.  Can anyone help me pointing where my mistake is?  Thanks.
    Peter
    Attachments:
    Array test.vi ‏19 KB

    It's a classic issue for LV newbies. In this case you HAVE to use a
    shift register otherwise the modifications of previous cicles are lost.
    It's all easier than it's seems, see attached vi.
    bye,
    manga
    Attachments:
    Array test 2.vi ‏19 KB

  • Help with do loop

    do{     
    if((orderType != 'g') || (orderType != 'w')){     
    System.out.println("Please enter g or w only.");
    }while((orderType == 'g') || (orderType == 'w'));
    I need help with this loop... I have to make sure it will be able to pop the input back after the invalid input... i tried to fix it...wont stop and stay in same loop till it gets the valid before go to other loop... how? am i missing something?

    I know you've already been answered, but just a bit more...
    if((orderType != 'g') || (orderType != 'w'))That would always be true. All characters are either not equal to 'g' or not equal to 'w'.
    'x' : neither 'g' nor 'w'. Evaluates to true.
    'g' : not 'w', still evaluates to true.
    'w': not 'g', still evaluates to true.

  • Help me with for loop please...............

    hi guys i m just new bie as you know
    i gotta print these things........
    from 7 stars to 1 star........
    i did it like this but it only produce
    in this way,,,,,,
    how do we actually padding the space and print it as the example........
    help me guys whoever experts in for loops my code is........
    class triangle
         public static void main (String[] args)
              a(7);
         public static void a (int num)
              for (int j = num ; j > 0 ; j--)
                   for (int i = 0 ; i < j ; i++)
                        System.out.print("*");
                   System.out.println ();
    }

    You really need a better screen name,
    The problem is is that you want to print out a descending number of stars
    preceded by a number of spaces . the number of spaces for a line is the number of characters - number of stars so
              for (int j = num ; j > 0 ; j--)
    HERE print the required spaces!
                   for (int i = 0 ; i < j ; i++)
                        System.out.print("*");
                   System.out.println ();

  • I feel ashamed but would someone help me with for loops?

    Hello all,
    Firstly, apologies. I feel ashamed. I am not new to programming but new to Java, so imagine my frustration at my blatant stupidity why I can't get this for loop to work....
    public void initGame(String[] arrTemp) {
    for (int i = 0; i > 4; i++) {
    frmGameOptions.append("hello" + arrTemp[i] + "-" + txtBully);
    basically the above method does not work!
    arrTemp does contain elements, trust me!
    it seems at though the loop isn't even getting entered!
    please help me!!!!!!!!!!!!!!!
    poncenby

    i think you want
    for (int i = 0; i < 4; i++)
        frGameOptions.append("hello" + arrTemp[i] + "-" txtBully);
    a better way would be
    for (int i =0; i < arrTemp.length; i++){
        frGameOptions.append("hello" + arrTemp[i] + "-" txtBully);
    }

  • So close but need help comparing strings in different subforms with for loop - Livecycle ES

    For some reason I was not able to post this in the Livecycle ES forum, even though I've posted there often in the past.
    I have created a form that I almost have working and I'm hoping someone can help me.
    We have eight billing teams in our company and each team works anywhere from 1 - 4 different clients. The form is used to track, per Billing Rep, the number of items of mail that each billing r5ep works each day. What I'm needing to add at the bottom is a subform that tracks the totals by client. So I'm trying to get the form to loop through all of the existing subforms (and the subforms within them) and compare a cell int he bottom subform to a cell in the other subforms, which are dynamically added, and then total ONLY those items. My script however is not working.
    What I have now is:
    var repCount = form1.P1._rep.count
    var itemCount = form1.P1.rep._ItemSet.count
    for (x=0; x<repCount; x++)
         for (i=0; i<itemCount; i++)
              if(clientName.rawValue == P1.rep[x].ItemSet[i].client.rawValue)
              this.rawValue = this.rawValue + P1.rep[x].ItemSet[i].corresp.rawValue;
    It seems like this should work but I'm getting the following error:
    P1.rep[x] is undefined
    So what it looks like is I'm missing is the proper way to reference the objects in these subforms.
    The form is here: https://acrobat.com/#d=20gWXZ4sBm4OPV6oO76zSg
    If someone could take a look at it I would be so grateful.
    Thanks,
    Jo

    I don't know that anyone else will ever have a similar problem as what I was having, but I figured I would go ahead and post the solution, just in case....
    The error I was getting (P1.resolveNode("rep[" + j + "].ItemSet[" + i + "]") is null) was occuring because the variable itemCount needed to be referenced within the repCount For Loop. I also needed to resolve the node for the itemCount, which I wasn't doing.
    So...my old code was this:
    var repCount = P1._rep.count;
    var itemCount = P1.rep._ItemSet.count;   //this part was throwing the error. Needed to use resolveNode...and needed to not declare the variable until inside the first For Loop.
    var nTotal = 0;
    for (var j=0; j<repCount; j++) {
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                nTotal = nTotal + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    this.rawValue = nTotal;
    ...which wasn't working because it was trying to reference the count of the ItemSet right up front...but it needed to wait until it got inside the first iteration of the repCount subfields...AND it needed to have resolveNode used.
    The corrected code is:
    var repCount = P1._rep.count;
    this.rawValue = 0;
    for (var j=0; j<repCount; j++) {
        var itemCount = P1.resolveNode("rep["+j+"]")._ItemSet.count;  //corrected code...node is resolved and variable is declared within the first subform repCount.
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                this.rawValue = this.rawValue + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    ...which now works perfectly...and I'm throwing a party to celebrate! LOL
    Jo

  • Visa open and close with "for loops"

    Hello everyone
    In my program I used two "for loops" which include visa write and read for a RS32 port. it is not possible to close a devise with visa close as the out put is changed to 2D array!!! would you please help me with this error
    Attachments:
    ACU_232.png ‏108 KB

    sam009 wrote:
    Thanks for reply,
    It works for "for loop" but what about "event structure loop" still is error for that. 
    Right-click on the output tunnel and uncheck "Use Default if Unwired".  You will now be forced to wire the VISA Resource through each case.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Need help with the loop

    I'm a beginner. I'm trying to get this output
    Initial number of stars:
    7
    Here's my program. What's wrong with it? Please help
    import java.io.*;
    class starWedge
    public static void main (String[] args ) throws IOException
    int numStars; // the number of stars
    int row ; // current row number
    int star; // the number of stars in this row so far
    BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
    String inputData;
    // collect input data from user
    System.out.println( "Initial number of stars:" );
    inputData = userin.readLine();
    numStars = Integer.parseInt( inputData );
    row = 1;
    while ( row <= numStars )
    star = 1;
    star = numStars - star;
    System.out.print("*");
    star = star + 1;
    System.out.println(); // end each line
    row = row + 1;

    Okay the one thing that I see immediately is that your while loop never actully exits. Not once. Why? Well simple your exit condition is the row <= numStars, yet nither numStars nor row actually change their values within the loop. In short row always equals 1 and thus never is equal to greater than numStars and the while loop does not terminate.
    Second thing is that your star drawing logic is not correct. Meaning you have not told to draw the specific number of stars in one given line. For starters the System.out.println() command should be in the loop not outside it. For your purposes a for-loop nested within a while-loop is much better.
    If you think you know what's wrong your program than read no further and go try it on your own. But if you still have no clue below is my modification of your code that actually produces the pattern you want, it might provide you with more hints.
    import java.io.*;
    class starWedge{
    public static void main (String[] args ) throws IOException{
         int numStars; // the number of stars
         int row ; // current row number
         int star; // the number of stars in this row so far
         BufferedReader userin = new BufferedReader (new InputStreamReader(System.in));
         String inputData;
         // collect input data from user
         System.out.println( "Initial number of stars:" );
         inputData = userin.readLine();
         numStars = Integer.parseInt( inputData );
         row = 1;
         while (numStars > 0){
         for(star = 1; star<=numStars; star++){
              System.out.print("*");
         numStars = numStars - 1;
         System.out.println(); // end each line
    }

  • Move MCs with for loop?

    I'm trying to figure out a way to move movie clips with a for loop
    I've got 10 dots called dt1-dt10 and I want to be able to set them all to y = 200.
    I understand i can set i=1;i<11;i++
    like
    for(i=1;i<11;i++){
    dt+i._y = 200;}
    or
    for(i=1;i<11;i++){
    String("dt"+i)._y = 200;}
    but the rest of it is a mess and either doesn't work, or glitches. I have yet to find a for loop help file for moving multiple movie clips.

    If you just want to immediately change the positions of the instances, then using a for loop will work okay, you just need to use the bracket notation [ ] to have strings be interpreted as instance names...
    for(i=1;i<11;i++){
         this["dt"+i]._y = 200;

  • Issue with FOR loop in Nested BEGIN and END terminals

    Hi All,
    I am trying to fetch row by row using FOR loop on CURSOR.An i am getting Error attached screen shot:
    Below is the logic:
    Create Procedure TEST1() LANGUAGE SQLSCRIPT AS
    BEGIN
    AN01 = Select * from AN.View;
    AN02 = SELECT DISTINCT F1,F2,F3 from :AN01 GROUP BY F1,F2,F3;
    BEGIN
    DECLARE CURSOR ITEM_RULE FOR select F1,F2,F3 from :AN02;
    FOR V_ITEM_RULE AS ITEM_RULE DO
    SELECT * from TABLE1 where F1 = V_ITEM_RULE.F1;
    END FOR;
    END;
    END;
    Here i an getting data from AN01..Then finding the Distinct in AN02.
    On AN02 i am applying CURSOR...and for each row i wanted to find an entry in TABLE1 and do a calculation further.
    -- But when i am using a FOR loop in the Nested BEGIN i am getting below Error.
    -- I tried to Activate successful without FOR Loop.
    Any Suggestion on the above issue.
    Thanks
    kalyan

    Hi Kalyan,
    Your procedure is incomplete.
    Why are you looping to make a select that you do not use? What is the target for ITEM_RULE_GDS selection?
    Also, like it is currently exposed a JOIN is highly recommended.
    Are you just playing around with procedure or you really have a scope to do ?
    Regards, Fernando Da Rós

  • Help with Relay Loop

    In the attached picture inside the red circle is where I need help.  I'm trying to turn on 4 relays, it currently works but all the relays come on at the same time I need a 500ms pause between each relay and I can't seem to figure it out.  I would assume some kind of for loop would work I'm just not sure how to index the "Fan 1 switch", Fan 2 switch","Fan 3 switch", Fan 4 switch" into an array.
    Any help would be much appreciated
    Thanks,
    Attachments:
    help1.jpg ‏251 KB
    fanctrl_with_sound_detec1.vi ‏61 KB

    Here's one example, using just a numeric indicator as the state control. The State Machine is only slightly more involved.
    This example also shows one way to use an array to set your booleans to True/False.
    Good luck!
    Message Edited by LabViewGuruWannabe on 01-28-2008 12:36 PM
    Attachments:
    RelaysON-OFF.vi ‏47 KB
    RelaysON-OFF-BD.png ‏46 KB
    RelaysON-OFF-FP.png ‏32 KB

  • Need help w/ for loop, a do loop, and a do-while loop.

    Hello I have been trying to write a program that uses a for, do, and a do-while loop, but I am having trouble. I need the program that will prompt the user to enter two numbers. The first number must be less than the second number. I need to use a "for loop", a "do loop", and a "do-while loop" to display the odd numbers between the first number and the second number. For example, if the user entered 1 and 8, the program would display 3,5,7 three different times (one for each of the loops). Please help if you can. Thanks.

    boolean2009 wrote:
    Thank all of you all for responding.Youre welcome.
    Yes this is my homework, but my major does not even involve java i just have to take the class.Not our problem.
    And yes we are suppose to have all three in one program I do not know why,So you can learn all three types of loops (there is also an enhanced for loop to learn later on).
    but I just do not understand programming nor do i really want to.Once again not our problem.
    If anybody could help it would be much appreciated. thanks.Yes, a lot of people are willing to help you. No, none of them will do it for you. What you need to do is attempt the code and when you get stuck, post your code using the code button, include error messages, indicate which lines in your code genereate those error messages and ask specific questions.

  • I need help with a loop within an hour

    I need to make a loop that gives 100, 10, 1000, 100, 10000, 1000...
    I can use a for loop, if loop, while loop, and do while loop.
    Thanks

    warnerja wrote:
    sharkura wrote:
    warnerja wrote:
    sharkura wrote:
    Sorry warnerja. I know I should have done the same. I just couldn't help myself. I need to keep telling rubbish.
    :D
    ¦ {ÞIt's not too late to edit your spoon-fed solution, though the OP may have seen and copied it by now.And you know this isn't going to make the OP a programmer, unless he/she/it changes his/her/its stripes.
    ¦ {ÞYes, but its laziness will continue to be encouraged more than it should.Nah. It'll crash and burn on the next assignment.
    ¦ {Þ                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help with while loops

    Im trying to create a while loop that outputs the revers of a string, eg nice one
    would be "eno ecin" Assuming i already have declared a variable intital string that holds the string, how do i go about this does anyone have any problem solving techniques. The charAt method needs to be used.

    i have a exam on saturday and it was a previous exam question that im trying to get help with i need to understand the course material thanks, i know how to use while loops but have trouble getting my head around this question. ill show you my code however i know its completely wrong.
    now i know i hvae to use the charAt method to return a character located at the integer i
    so i must go down after each case has been tested true therefore i want i=i-1;
    until i=0;
    String initialString="tucan";
    int i=initialString.length();
    while(i>0)
         return charAt();
         i=i-1;
         }

  • Help req for loop

    Hi All,
    I am retriving values from database and then writing it to a file...The code for this is
    String query = "SELECT Project_Master.proj_name,Project_Master.proj_desc,Project_Master.proj_location,folder_navigation.nav_name, content_document.cont_name,content_document.cont_type FROM Project_Master INNER JOIN folder_navigation ON Project_master.proj_id=folder_navigation.proj_id INNER JOIN content_document ON content_document.nav_id = folder_navigation.nav_id ";
    ResultSet rs = stmt.executeQuery(query);
    int maxcols = rs.getMetaData().getColumnCount();
    while(rs.next())
    System.out.println("proj_name::"+rs.getString("proj_name"));
    System.out.println("proj_desc::"+rs.getString("proj_desc"));
    System.out.println("proj_location::"+rs.getString("proj_location"));
    System.out.println("nav_name::"+rs.getString("nav_name"));
    System.out.println("cont_name::"+rs.getString("cont_name"));
    for(int i =1;i <=maxcols;i++)
    myData.add(new Tags_Define(rs.getString("proj_name"),rs.getString("proj_desc"),rs.getString("proj_location")));
    I get output of this as
    <name>data1</name>
    <desc>data2</desc>
    <path>data3</path>
    this data is repeated 6 times as there are 6 colomns in my table
    If i comment out for loop i get the above data 2 times
    But I want data to be retained row wise
    What should i do?
    Please help
    Thanks in advance

    First of all, when posting code, click the code button.
    Is the for loop meant to be nested in the while or is it supposed to come after it? It is impossible to tell as you did not include the closing brace.
    Also this code:
    String query = "SELECT Project_Master.proj_name,Project_Master.proj_desc,Project_Master.proj_location,folder_navigation.nav_name, content_document.cont_name,content_document.cont_type FROM Project_Master INNER JOIN folder_navigation ON Project_master.proj_id=folder_navigation.proj_id INNER JOIN content_document ON content_document.nav_id = folder_navigation.nav_id ";is much longer than it needs to be. Are you sure it executes without errors? Why don't you use a table alias instead?
    String query = "SELECT PM.proj_name,PM.proj_desc,PM.proj_location,folder_navigation.nav_name, content_document.cont_name,content_document.cont_type
    FROM Project_Master PM INNER JOIN folder_navigation ON PM.proj_id=folder_navigation.proj_id INNER JOIN content_document ON content_document.nav_id = folder_navigation.nav_id ";also, you have not specified folder_navigation or content_document in the from clause, I presume these are also tables? Also, what is myData? We do not see it declared anywhere.

Maybe you are looking for

  • HT201365 help ?

    i have a problem with activation my iphone 5. my iphone as for icloud adres for acctivation but in www.icloud.com my phone not is pressent my icloud adress is [email protected] help pls how to regisster my device in icloud i can't activate my iphone

  • My headphone jack isn't recognizing my headphones

    I just bought a 7th gen Ipod nano.  My headphones work fine, but my Ipod isn't recognizing them at all. I tried resetting the settings, but that didn't work. I tried another set of headphones and that didn't work either.

  • How to display Formatted text view in adobe forms

    Hi Folks, We have a element formatted text edit/view in webdynpro so it is easy to make the text formates(Bullets, font sizes, etc..) in webdynpro, but the same feature is not available in Adobe forms designer...I don't find any element in the Adobe

  • Certificates with no Exchange Services assigned - what to do with them?

    In the Exchange Control Panel, I see 6 certificates - 3 are used for Exchange Services, three have no services assigned to them.  If we delete these certificates from the ECP, will they also get deleted from the Computer's Personal store, or are they

  • Datasource is getting created without jndi name

    <?xml version="1.0" ?>      <project name="deploy" default="createDataSource" basedir=".">      <property name="weblogic.jar" location="C:/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar"/>      <property name="wls.username" value="weblogic"