A 'For' loop within another 'For' loop

This is the loop:
for (int i = 1; i<=5; i++) {
for (int k = 1; k<=3; k++) {
System.out.println("i is " + i + ", k is " + k);
How does it execute? After it goes through the loop i = 1, and k = 1, apparently it then doesn't go to i = 2, but instead it increments k to 2, and i remains as 1 until k is greater than 3. I'm confused how this works. Does the first loop execute first, and then the second loop executes, but then the program exits out of the second loop only when k is greater than 3?
Much appreciate your help.
Yash

Try to imagine expanding the loops. In the example you provided, the loops aren't that big, so it's pretty easy.
for (int i = 1; i<=5; i++) {
  for (int k = 1; k<=3; k++) {
    System.out.println("i is " + i + ", k is " + k);
}becomes
int i = 1;
  for (int k = 1; k<=3; k++) {
    System.out.println("i is " + i + ", k is " + k);
i = 2;
  for (int k = 1; k <= 3; k++) {
    System.out.println("i is " + i + ", k is " + k);
i = 3;
  for (int k = 1; k <= 3; k++) {
    System.out.println("i is " + i + ", k is " + k);
i = 4;
  for (int k = 1; k <= 3; k++) {
    System.out.println("i is " + i + ", k is " + k);
i = 5;
  for (int k = 1; k <= 3; k++) {
    System.out.println("i is " + i + ", k is " + k);
  }which becomes
int i = 1;
  int k = 1;
    System.out.println("i is " + i + ", k is " + k);
  k = 2;
    System.out.println("i is " + i + ", k is " + k);
  k = 3;
    System.out.println("i is " + i + ", k is " + k);
i = 2;
  k = 1;
    System.out.println("i is " + i + ", k is " + k);
  k = 2;
    System.out.println("i is " + i + ", k is " + k);
  k = 3;
    System.out.println("i is " + i + ", k is " + k);
i = 3;
  k = 1;
    System.out.println("i is " + i + ", k is " + k);
  k = 2;
    System.out.println("i is " + i + ", k is " + k);
  k = 3;
    System.out.println("i is " + i + ", k is " + k);
i = 4;
  k = 1;
    System.out.println("i is " + i + ", k is " + k);
  k = 2;
    System.out.println("i is " + i + ", k is " + k);
  k = 3;
    System.out.println("i is " + i + ", k is " + k);
i = 5;
  k = 1;
    System.out.println("i is " + i + ", k is " + k);
  k = 2;
    System.out.println("i is " + i + ", k is " + k);
  k = 3;
    System.out.println("i is " + i + ", k is " + k);

Similar Messages

  • XSLT for-each within another for-each

    Hi All,
    My XSLT mapping needs to pick a field(BOL) from the Header and the using that, search the Items node for the matching BOL and generate the output accordingly.
    My current XSLT is as follows(not the entire program, just the snippet)
         <xsl:for-each select="ns0:Messages/ns0:Message1/ns1:MT_Header/Header">
                          <xsl:param name="search"><xsl:value-of select="bol"/></xsl:param>
         <xsl:for-each select="ns0:Messages/ns0:Message2/ns1:MT_Items/Item[BOL=$search]">
                  <Output>
                     <BOL_ITEM><xsl:value-of select="BOL_ITEM"/></BOL_ITEM>
                </Output>     
         </xsl:for-each>
         </xsl:for-each>
    The following code works correctly(without the outer for-each and with hardcoding)
                             <xsl:param name="search">100</xsl:param>
         <xsl:for-each select="ns0:Messages/ns0:Message2/ns1:MT_Items/Item[BOL=$search]">
                  <Output>
                     <BOL_ITEM><xsl:value-of select="BOL_ITEM"/></BOL_ITEM>
                </Output>     
         </xsl:for-each>
    So its the for-each within another for-each that does not work . Is there some syntax problem ? Or another way to achieve this in XSLT?

    Closing this thread

  • Fire event from within another event ?

    It seems that an event fired from within another event does not
    actually execute its code until the firing event completes. The fired
    event's Time value in its Event Data Node indicates the time that it
    was told to execute, but using GetTickCount calls shows that its code
    does not execute until the firing event is finished. This happens
    whether Value Signaling is used to generate a Value Change event or if
    CreateUserEvent and GenerateUserEvent is used. Is this because events
    are placed in a queue ? This behavior is different from Delphi for
    example where the fired event executes right away when called from the
    firing event (before the firing event completes).
    I have an event that executes upon a button value change. I would
    like that same event's code to execute when another button is pressed,
    but also have other code in the second button's event execute after
    that first button's event's code completes. Is there another way to
    accomplish this ?
    Steve

    > It seems that an event fired from within another event does not
    > actually execute its code until the firing event completes. The fired
    > event's Time value in its Event Data Node indicates the time that it
    > was told to execute, but using GetTickCount calls shows that its code
    > does not execute until the firing event is finished. This happens
    > whether Value Signaling is used to generate a Value Change event or if
    > CreateUserEvent and GenerateUserEvent is used. Is this because events
    > are placed in a queue ? This behavior is different from Delphi for
    > example where the fired event executes right away when called from the
    > firing event (before the firing event completes).
    I'm not that familiar with Delphi, but LV events are asynchronous.
    Window
    s OS has two ways of firing events, Send and Post. The LV events
    are always posted. The primary reason is that the LV events are handled
    by a node, not by a callback. The node you are calling is in the middle
    of a diagram, and reentering it not valid.
    > I have an event that executes upon a button value change. I would
    > like that same event's code to execute when another button is pressed,
    > but also have other code in the second button's event execute after
    > that first button's event's code completes. Is there another way to
    > accomplish this ?
    The best way to reuse code is to use subVIs. Firing events, or rather
    sending events is pretty close in other events to making a function call
    dispatched to anyone interested in the event. The event just hides who
    you are calling and makes you put your parameters in a funny format
    stuffed inside the event. IMO it also makes the code very hard to read
    since you don't know what calls what.
    Instead, just put the code into a sub
    VI and call it whenever you need
    to, from the event structure in one or more locations, and from other
    loops and diagrams.
    Greg McKaskle

  • PL/SQL: Executing a procedure from within another procedure

    Hello, I'm a newbie and I need help on how to execute procedures from within another procedure. The procedure that I call from within the procedure have return values that I want to check.
    I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    but I get the error message:
    PLS-00103: Encountered the symbol "USER_GET_FORUM_INFO" when expecting one of the following::= . ( @ % ; immediate
    The symbol ":=" was substituted for "USER_GET_FORUM_INFO" to continue.
    And when I tried: EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    I get the error message:
    PLS-00222: no function with name 'USER_GET_FORUM_INFO' exists in this scope
    PL/SQL: Statement ignored
    The procedure USER_GET_FORUM_INFO exists. (don't understand why it says "no FUNCTION with name", it's a procedure I'm executing)
    I'm stuck so thanks for any help...
    Below is all the code. I'm using Oracle 9i on RedHat Linux 7.3.
    ================================================================================
    CREATE OR REPLACE PROCEDURE user_forum_requestsaccess (
    p_forumid IN NUMBER,
    p_requestmessage IN VARCHAR2
    AS
    var_forumid NUMBER;
    var_forum_exists NUMBER;
    var_forum_access NUMBER;
    request_exists NUMBER;
    var_forumname VARCHAR2(30);
    FORUM_DOESNT_EXIST EXCEPTION;
    FORUM_USER_HAS_ACCESS EXCEPTION;
    FORUM_REQUEST_EXIST EXCEPTION;
    BEGIN
    SELECT SIGN(NVL((SELECT request_id FROM forum.vw_all_forum_requests WHERE forum_id = p_forumid AND db_user = user),0)) INTO request_exists FROM DUAL;
    EXECUTE(user_get_forum_info(p_forumid, var_forum_exists, var_forum_access, var_forumname));
    IF var_forum_exists = 0 THEN
    RAISE FORUM_DOESNT_EXIST;
    ELSIF var_forum_access = 1 THEN
    RAISE FORUM_USER_HAS_ACCESS;
    ELSIF request_exists = 1 THEN
    RAISE FORUM_REQUEST_EXIST;
    ELSE
    INSERT INTO tbl_forum_requests VALUES (SEQ_TBL_FORUM_REQ_REQ_ID.NEXTVAL, SYSDATE, p_requestmessage, p_forumid, user);
    INSERT INTO tbl_forum_eventlog VALUES (SEQ_TBL_FORUM_EVNTLOG_EVNT_ID.NEXTVAL,SYSDATE,1,'User ' || user || ' requested access to forum ' || var_forumname || '.', p_forumid,user);
    COMMIT;
    END IF;
    EXCEPTION
    WHEN
    FORUM_DOESNT_EXIST
    THEN RAISE_APPLICATION_ERROR(-20003,'Forum doesnt exist.');
    WHEN
    FORUM_USER_HAS_ACCESS
    THEN RAISE_APPLICATION_ERROR(-20004,'User already have access to this forum.');
    WHEN
    FORUM_REQUEST_EXIST
    THEN RAISE_APPLICATION_ERROR(-20005,'A request to this forum already exist.');
    END;
    GRANT EXECUTE ON user_forum_requestsaccess TO forum_user;
    ================================================================================
    Regards Goran

    you don't have to use execute when you want to execute a procedure (only on sql*plus, you would use it)
    just give the name of the funtion
    create or replace procedure test
    as
    begin
        dbms_output.put_line('this is the procedure test');
    end test;
    create or replace procedure call_test
    as
    begin
        dbms_output.put_line('this is the procedure call_test going to execute the procedure test');
        test;
    end call_test;
    begin
        dbms_output.put_line('this is an anonymous block calling the procedure call_test');
        call_test;
    end;
    /

  • Background job within another background job

    Hello Experts,
    I have a BDC program (for BW tcode OLI7BW) which executes by scheduling a number of background jobs. This report works fine when run manually. But doesn't work if it is scheduled as a background job through SM36. The status of the job is shown as finished, but the data is not uploaded.
    Is it not possible to execute a background job within another background job?
    If it's possible, what could be the possible cause of error?
    Thanks In Advance
    Radhika

    Hi Radhika,
    If you are trying to upload data from a file on ur desktop to Internal table, then background job doesn't work. Always remember GUI means ur front end and all background jobs are run on application server and they dont run w.r.t ur desktop.
    Kindly check it and get back to me incase of any queries.
    Dont forget to reward points, if found useful.
    Thanks and Regards,
    Satyesh

  • Can I use an event structure within another event structure

    Hi
    Can use an event structure within another event structure?
    Thanks
    Yasamin
    Solved!
    Go to Solution.

    I attached my Vi from my old project (MY OLD VI). It is worked correctly.
    But I decided that use event structure instead of case structure.
    I attached my new VI as a picture and as a LabVIEW VI too (network_analyzer_8510_920527 Frequency Sweep.vi )
    My graphs show by pressing "case 5: button (Bottom of page right hand).
    Then I want to show each of graph in a large window( in a new VI) by clicking a key (for example "show 1").
    Thanks
    Yasamin
    Attachments:
    my VI.JPG ‏256 KB
    network_analyzer_8510_920527 Frequency Sweep.vi ‏72 KB
    MY OLD VI.vi ‏69 KB

  • Indexing - one document embedded within another

    Greetings,
    I am testing KM indexing in terms of examining how Trex handles the indexing of a scenario where you have one document embedded within another document.
    In this case I have chosen to embed a PowerPoint (.ppt document) within a Word document (.doc document).
    I index the Word document, expecting to therefore also have the PowerPoint document within indexed. When I search for the text within the embedded .ppt document I do not get results and therefore assume that Trex cannot index documents which are embedded in other documents. Please advise if I am correct. 
    Regards,
    Keith

    >
    Keith Kibuuka wrote:
    > Greetings,
    >
    > I am testing KM indexing in terms of examining how Trex handles the indexing of a scenario where you have one document embedded within another document.
    >
    > In this case I have chosen to embed a PowerPoint (.ppt document) within a Word document (.doc document).
    >
    > I index the Word document, expecting to therefore also have the PowerPoint document within indexed. When I search for the text within the embedded .ppt document I do not get results and therefore assume that Trex cannot index documents which are embedded in other documents. Please advise if I am correct. 
    >
    > Regards,
    > Keith
    Hi Keith,
    yes that's exactly correct from my knowledge's point of view.
    I had a similar issue with an HTML-document that contained another HTML-document as iframe and this is also not possible (I asked SAP about this, so for this I am sure).
    TREX does anyway a transformation for all sort of documents to HTML documents (so also DOCs or PDFs are firstly converted to HTML before they are indexed). And in here TREX never follows any embedded content.

  • Run a BR or Calc Script within another BR

    Is there a way from which I can run one Business Rule/Calculation Script in another Business Rule/Calculation Script (Run one BR/Calc Script within another BR)?
    Edited by: 930603 on May 3, 2012 4:44 PM

    Hi,
    Do you want to run two BR's parallel y, why you are not going for sequences option, you can divide your rule in parts and run the rules in the sequence you want.
    run one Business Rule/Calculation Script in another Business Rule/Calculation Script (Run one BR/Calc Script within another BR)?I don't think so you can call one BR from other, if you want the same might be you have to write CDF for calling the BR/CalcScript within the BR. or you can use Essbase Macro option.(+I am not sure for this option+)
    Thanks,
    Avneet Singh Bhatia

  • Will google list a splash page made within another website in iWeb?

    I've tried submitting a website to google multiple times but they aren't picking it up/listing it. I'm wondering if that is because it is set up as a splash page within another website. I'm trying to get nateweldon.com listed, but it is built within the seaserpentrecords.com website I made in iWeb. It is a hidden page I've set up within seaserpentrecords.com to save money on hosting. Any tips to make nateweldon.com searchable in google?
    Thanks so much for any help.
    Ellen

    Where do you publish your website - MobileMe or another server?
    Are you using masking to forward the domain name - nateweldon.com ?
    Splash pages and masking are two of the things to be avoided with SEO.
    If you have only one root folder on your server you need to publish the nateweldon site as a sub site with its own folder so that its URL is...
    http://www.seaserpentrecords.com/nateweldon/
    Create and upload a sitemap.xml for the above URL and upload it to the nateweldon folder....
    http://www.iwebformusicians.com/Search-Engine-Optimization/Sitemap.html
    "I may receive some form of compensation, financial or otherwise, from my recommendation or link."

  • Problem with calling a midlet within another midlet

    hello friends,
    can a create an instance of a midlet within another midlet.i tried to call , but i have got a Security exception. plz comment on this ..
    regards..

    "For security reasons, it is assumed that MIDlets within a MIDletSuite are packaged
    together for a reason and should be able to interoperate. What's implied here is that the
    MIDlets share a name space; in other words, each MIDlet in the MidletSuite can "see" one
    another. Because they can see one another, they can launch one another (Class.forName
    metaphor).
    In contrast, one MIDletSuite cannot launch another MIDletSuite. That's because they do not
    share name spaces. Since the CLDC+MIDP does not have a security manager (too big and
    complex for small devices), the MIDP expert group felt it more prudent to limit the interaction
    of downloaded applications to those that are packaged together by the provider."extract from Sun
    see http://developers.sun.com/mobility/midp/articles/pushreg/ for infos to launch MIDlets...

  • Need help to call a simple function from within another function?

    I created a movieclip which has a function in its one and only frame.
    function testx() {
    x = x+2};
    This movieclip is in the main timeline (in its own layer).
    In another layer on the timeline I have created a single keyframe with a button instance called myBtn
    myBtn.onRelease = function() {
    var x
    x =2
    testx(2);
    trace (x);
    What I want to do is call the function in the movieclip frame from the button press function. However, I can't seem to reference it properly.
    Can anyone help me to basically call a simple function from within another function?

    Yes am using CS4.  Have saved it as CS3 now.  Ok the file is somewhat complicated and what I am testing is not what I ultimately want to do but if I can pass that variable I can figure it out.  In terms of describing the file I think the only parts of importance are what I put in my previous post (please let me know if there is something I should be telling you that I have missed).  I am 99.9% sure that I am using the correct instance name.
    Scene1 Layer3 Frame1 has the function call for the button.
    myBtn.onRelease = function() {
    var x
    x = 2
    testx(2);
    trace (x);
    Slideshow layer //Actions Frame1 has the function
    function testx(x) {
    x = x+2};
    thank you so much for helping me.

  • Command to display only the latest modified directory within another directory and display the date of the last modify

    Okay I want to be able to run a .cmd file from my workstation to query a certain folder on remote clients. I want the command to find the specific folder within another folder and display the current date modified of that folder. I was
    able to use a command prompt to list the subdirectory that I was looking for on a specific computer by using the
    DIR command. It was something like this:
    dir C:\ParentFolder\ChildFolder /ad /o-d /b
    This shows a list of directories within the "ChildFolder" directory. The output would be something like:
    dir C:\ParentFolder\ChildFolder /ad /o-d /b
    folder1
    folder2
    folder3
    folder4
    So what I need now is a way to just show the folder in this group that had the most recent modification. For example if "folder2" was the most recently modified folder in the group, I would like my command line to just display "folder2 04/08/14
    04:13 PM
    Any help would be greatly appreciated.
    Cheers!

    Thanks Mike! This is what I was looking for! Much appreciated!
    I would like to run this as a script from my admin workstation that will query clients that have the "ChildFolder" directory. Is there a way to output the results to a .log/.txt file? I was working on .cmd that looked like this:
    {REM Verify current folder on remote clients
    del current-folder.log
    ECHO WorkStation-1 >> CurrentFolder/current-folder.log 2>&1
    ECHO ---------------- >> CurrentFolder/current-folder.log 2>&1
    DIR \\WorkStation-1\C$\ParentFolder\ChildFolder /ad /o-d /b >> CurrentFolder/current-folder.log 2>&1
    ECHO ---------------- >> CurrentFolder/current-folder.log 2>&1}
    My results looked something like this:
    " WorkStation-1
    Folder1
    Folder2
    Folder3
    I know it's ugly, but it was working (somewhat). I just needed to list only the most recently modified folder. Anyway, I've rambled enough.
    Is there a way to get my desired results using the PS command that you provided me?

  • How do I create a table within another table?

    How do I create a table within another table?
    As shown in image below (document created with Words), I already have a table with 3 columns. How do I create another table with 6 columns to tabulate the data (the one below "3.1 Overall")?

    Last time I checked in Pages 5.5.2 that is not possible.
    Peter

  • Invoking the main() method of a class within another

    Greetings -
    Can someone tell me what happens when you invoke the main() method of a class from within another class?
    I have a third-party class, designed to be invoked from a command line, that I want to invoke from within a separate class. What appears to be happening is that following the successful execution of the third-party class, the invoking class is terminated as well. That's not the intended behavior I had envisioned. ^_^
    Is there a better way than invoking the main() method? I still need the invoking class to continue executing.
    Thanks!

    Navigate yourself around pitfalls related to the Runtime.exec() method

  • Creaing a BA within another BA

    Hi,
    Whether it is possible to create a Business Area within another Business Area. If so, how can I achieve this.
    Thanks&Regards
    P.Velvadivu.

    No, it is not possible to have Business Area's within Business Area's.

  • Call a external SWF by press the button within another SWF file but the second SWF file play Externely

    Hello Guyz.
    i am working on Macromedia Flash 8 and i just want to call a external SWF when i press the button within another SWF file.......but the second SWF file play Externely............can any one knows the code.... AS2

    try this
    http://www.actionscript.org/forums/showthread.php3?s=&threadid=28123

Maybe you are looking for