VERY IMPORTANT FOR LOOP QUESTION

public class ForTest2 {
     public static void main(String args[]) {
          int i=0, j = 0;
          for (j=0; j < 10; j++) {
               i++;
               System.out.println("i is: " + i);
               System.out.println("j is: " + j);
          System.out.println("Final i is: " + i);
          System.out.println("Final j is: " + j);
}j ends up being 10. Why? It should only be 9. This is as when j is 10 the for loop fails, so j++ shouldnt happen.

First, please, please, please stop using all caps. It's extremely annoying.
Second, don't mark your question as urgent or important. It is 100
% guaranteed NOT to get you help any faster, and it might just delay you getting help because it's annoying.
As for your question, you're misunderstanding how the for loop works. j HAS to become 10 for it to end. The loop body executes as long as j < 10. If j didn't become 10, the loop body couldn't terminate, because j<10 would always be true.
The body is executed, the j++ is executed, then the j<10 is tested.
int j;
for (j = 0; j < 10; j++) {
    // body
// is equivalent to
int j;
j = 0;
while (j < 10) {
    // body
    j++:
}

Similar Messages

  • HT204022 Dear sir/madam,  I had accidentally deleted all my images from my iPhone 4s do u send me any solution or my phone back up. please sir its very important for me i have just one hope from you.  Thank you  

    I had accidentally deleted all my images from my iPhone 4s do u send me any solution or my phone back up. please sir its very important for me i have just one hope from you.
    Thank you  

    Use the backup you make to iCloud or a computer.
    iTunes: About iOS backups - http://support.apple.com/kb/HT4946

  • I want download  other apps from web links .but i cant open ? Can u help me how i downelod in my i  its very important for me these apps related from my business . So kindly sugest me

    Dear sir
    am using i6+. Iam facing some problems regarding apps download . I just start using iPhone.
    my problem is when i go for download some apps from web page I can't download only some zip shows on 2nd web page i mean whin i click on download link for som app atumaticaly open another broswing page and zip and app name shows but I can't install that app in my iphone .
    all thes apps very important for my business.
    kindly  sugest me how can i insttal these aaps in my iPhone.these apps not avlable in google play store and itune app store .
    wat can i do ?

    The ONLY apps that can be installed will be found in the iTunes app store.
    You cannot load any other apps at all.

  • Why can't we see the details of a picture or video taken with our iphone or Ipad? Detail like when it was taken the picture or when the movie was filmed. I think that this very very important for our memories.

    Why can't we see the details of a picture or video taken with our iphone or Ipad? Detail like when it was taken the picture or when the movie was filmed. I think that this very very important for our memories.

    Yes, I know that, but it was easier to see it on the Iphone self, like the other company phones. The name of the picture taken should be the date when it was taken.

  • Cursor For loop question

    Hi,
    I have a cursor in my plsql and I am trying to get the record through a FOR loop. I know that for loop will take care of opening, fetching and closing the cursor implicitly.
    Ex.
    declare
    cursor c1 is
    select * from emp;
    begin
    for l_rec in c1 loop
    end loop;
    My question is i want to check whether the cursor in the for loop is returning any record or not using IF condition.
    where and how i will find that?
    Can anyone help how to do that.
    Rds,
    Nag

    without using boolean variables.Obvious question, WHY?
    If you are so particular..
    SQL> declare
      2   cursor c1 is
      3        select empno, ename, job
      4        from emp
      5        where empno = 7839123;
      6   ex exception;
      7   rec c1%rowtype;
      8  begin
      9   open c1;
    10   fetch c1 into rec;
    11   if c1%notfound then
    12    raise ex;
    13   end if;
    14   loop
    15    dbms_output.put_line(rec.empno||'-->'||rec.ename||'-->'||rec.job);
    16    fetch c1 into rec;
    17    exit when c1%notfound;
    18   end loop;
    19  exception
    20   when ex then
    21    dbms_output.put_line('cur not found');
    22  end;
    23  /
    cur not found
    PL/SQL procedure successfully completed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • For loop question

    Hi here is a segment of my code:
    public void vietaLoop(){
         int loopParameter;
         final int START_CONDITION=0;
         final long END_CONDITION=no_Terms;
         double initialTerm = Math.sqrt(2)/2;
         double newTerm;
         double previousTerm;
         /* calculate the next PI term */
         newTerm = Math.sqrt(2+previousTerm);
         /* assign new term to previous */
         previousTerm = newTerm;
         for (loopParameter = START_CONDITION; loopParameter < END_CONDITION;
         loopParameter++)
         /* Prints the new PI approximation */
         System.out.println(+ newTerm);
    im having loads of trouble, above is how far I have got but I'm unable to 'call' the previous calculation to be included in the next calculation to calculate the new term of PI. as a result all my output is the same..... ie = 1.645.......
    If anyone could point me in the right direct... its really getting to me. Thanks.

    Hi there,
    Is this what you want?
    import java.awt.*;
    class vietaLoop
        public static void main(String[] args)
              int loopParameter;
              int no_Terms=10;
              int START_CONDITION=0;
              int END_CONDITION=no_Terms;
              double initialTerm=Math.sqrt(2)/2;
              double newTerm;
              double previousTerm;
              previousTerm=initialTerm;
              for (loopParameter=0; loopParameter<END_CONDITION;loopParameter++)
                   newTerm = Math.sqrt(2+previousTerm);
                   previousTerm = newTerm;
                   System.out.println(newTerm);
    }If you use it as a function, set it as
    public double vietaLoop(int noTerm)
    Then you can change no of term for looping.
    Regards
    John

  • A simple for loop question

    Hi
    Lets say I have an array with boolean values in it:
    my_array = [ false , false , false ]
    My question is:
    How do you make a function to check, if the value is all
    false, than do this (not only one but all false than trigger a
    function)
    thank you

    The 350Z,
    > Lets say I have an array with boolean values in it:
    > my_array = [ false , false , false ]
    I'm with ya.
    > My question is:
    > How do you make a function to check, if the value is
    > all false, than do this (not only one but all false than
    > trigger a function)
    Your subject line already states the answer. A for loop
    would come in
    handy. :) In your case, you're looking for all three values
    to be false.
    If even a mere one of them is true, the whole result doesn't
    count. Let's
    write a function that returns true if all three are false,
    and returns false
    if any are true.
    function checkWholeArray(arr:Array):Boolean {
    for (var n:Number = 0; n < arr.length; n++) {
    if (arr[n] == true) {
    return false;
    return true;
    To use this function, you could call it and supply your
    array as the
    parameter ...
    checkWholeArray(my_array);
    ... and since that resolves to either true or false, you
    could even use that
    expression in an if statement.
    if (checkWholeArray(my_array)) {
    // do something
    } else {
    // do something else
    The for loop simply steps through each element in the
    passed-in array.
    If the current element is true, then the desired outcome --
    that all
    elements are false -- is a loss, so the function returns
    false and
    immediately stops (the return statement always exits the
    function at that
    point). Otherwise, the for loop finishes, and the function
    returns true.
    David
    stiller (at) quip (dot) net
    Dev essays:
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Tomcat Wiki: very important for newbies

    Hi everyone!
    I have a very important suggestion (important for newbies or ... me) for the tomcat wiki. To work with tomcat without problems you must have permissions on the configuration files. So i think the wiki must have something related to permissions and groups like
    gpasswd -a <user> tomcat.
    All the configuration files bundled with the tomcat package doesn't have the permissions for any user to read its content. The only easy way to have access to this files is adding your user to the tomcat group.
    I hope this helps.
    See ya!
    PD: sorry if you notice my poor english.

    Would that fix this mod_jk problem? Do you mean to say that I have those permissions when I actually edit those files?
    I think the wiki is also mistaken assuming that JAVA_HOME is in the /opt directory.

  • Insert Procedure For LOOP question

    Hi all,
    I have made a Procedure which basically massages data and loads into into another table and makes a time record aswell. I am practising my good datawarehousing practise (So load table into real DW_table)
    I am using an Explicit Cursor For Loop....
    What i was wondering is if there is some type of SQL%rowcount I can do in order to check that the record where "INSERTED" into dw_client and dw_time; before i create a auit record in another table. I know this is normally done using triggers, but I am testing this for a Datawarehouse and not sure triggers are the best answer. But please correct me if im wrong:
    I basically wanted to put another insert in there, if the inserts actually ran!

    RPuttagunta wrote:
    Why can you not use a merge statement in your code instead of writing a whole procedure for it?
    merge into mehmet_schema.dw_client a
    using
    mehmet_schema.client.....
    If I understand it right, you are checking if there are any records that exists in 'client' and doesn't exist in 'dw_client' table, then, you are inserting. Is that correct?Yes that is correct. Also I am inserting into the dw_time table using the sqeuence values, so i didnt think merge statement would do this!
    aslo i wanted to use this procedure to clean up some of the data, as you can see in my Cursor, again why i havent used a merge
    Edited by: oraCraft on 09-Nov-2010 09:53

  • Quick for loop question

    Hi everybody,
    I have a feeling this is so obvious that I'm missing it, so if anyone would give me some advice, I'd appreciate it.
    I have a method with with three parameters that loops through them and progressively adds or subtracts them with a for loop, based on the order. The only way I can think of to do this, though, is with two for loops with almost identical code. I know there must be an easier way to do this, but I think I've been staring at it too long, can anyone give me a hand conceptually, please?
    The method is:
    private void create( int param1, int param2 ) {
            int entries = 5;
            double increment;
            if( param1 > param2 ) {
                increment = param1 - param2;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 - ( i * increment ) );
            } else if( param2 > param1 ) {
                increment = param2 - param1;
                for( int i = 0; i < entries; i++ ) {
                    System.out.println( param1 + ( i * increment ) );
         }Thanks,
    Jezzica85
    Edited by: jezzica85 on Mar 30, 2009 2:38 PM

    private void create( int param1, int param2 ) {
        if( param1 > param2 ) {
            create(param2, param1);
        } else if( param2 > param1 ) {
            int entries = 5;
            double increment = param2 - param1;
            for(int i = 0; i < entries; i++ ) {
                System.out.println( param2 + (i * param1));
        } //equal do nothing?
    }or
    private void create2( int param1, int param2 ) {
        if (param1 != param2) {
            int entries = 5;
            int minParam = Math.min(param1, param2);
            int maxParam = Math.max(param1, param2);
            double increment = maxParam - minParam;
            for( int i = 0; i < entries; i++ ) {
                System.out.println( maxParam - (i * minParam));
      }

  • Enhance for loop question

    I like it, but I can't figure out how to use it for the following situation (printing contents of two arrays using one iterator):
    old way:
            System.out.println(menuTitle + "/n");
            for (int e ; e < length.menuChoices ; e++)
                System.out.print(menuChoices[e] + " - " + menuLabels[e]);
            }new?
            System.out.println(menuTitle + "/n");
            for (String e : menuChoices)
                System.out.print(e + " - " + menuLabels[????]);
            }Is there a nice way to do this or should I just use the old for loop and hope my teacher doesn't think that I just don't know about the new loop? Thanks.

    Is there a nice way to do this or should I just use
    the old for loop and hope my teacher doesn't think
    that I just don't know about the new loop?No there isn't. In the new for-loop the loop counter has been abstracted away. You'll have to either use the old for-loop, or introduce a counter in the new.
    Another way could be to change the design a little.
    class MenueItem {
       Type1 choice();
       Type2 label();
    for (String e : menuItems)  { // all MenuItems
       System.out.print(e.choise() + " - " + e.label());
    }

  • Stacked sequence inside for loop question

    Hi everyone,
    I am new to LabVIEW and I just want to make a for loop with a stack sequence inside. I want it so that when the for loop executes for the n-th time, the stacked sequence is at the n-th frame (because each frame contains different tasks to be carried out). Is this possible? or is there an alternative equivalent method? Please help me out! Thanks!!

    Thank you Norbert for the words of advice.
    Try to avoid Stacked Sequence Structures at all cost.  They are a nightmare to deal with when maintaining the code and they do not offer simple scalability, especially if you need to deal with parallelism.
    As Norbert suggested, State Machines is the way to go.  Try to avoid naming covention such as 1...2...3...4...5.......9999.  Give the name of each case based on what that case does.  Create a TypeDef Control for the state selector (you'll thank me after having changed it for the 5th time   ).
    There are probably 100's of examples in this forum.
    RayR

  • Very very important for me... Can I Found old versions of apps that are compatible whith my ios?

    I have a 2G ipod touch and I had to restore it... Can I Found old versions of apps that are compatible whith my ios? I can't download apps because they need ios 5.0 or superior.
    Now I have no apps installed because I didn't found anyone compatible.
    I need apps like pdf readers, gmail... The most importat for me now is a PDF Reader, only with a solution for this I wold be very happy.
    I'll be very grateful if you answer this question. Please, I need help.

    If you previously purchased the app you may be able to redownload by:
    'Last Compatible' Version of Apps for Users Running Legacy Versions of iOS - Mac Rumors
    To more easily find compatible apps:
    iOSSearch - search the iTunes store for compatible apps.
    Apple Club - filter apps by iOS version.

  • Hi please provide me an solution for this..its very important for me..plz

    march      april a/c     may     june     july
    30 dpd          100     105     110     120     120
    60dpd          80     75     80     90     85
    90 dd          60     65     60     70     70
    120 dpd          40     35     40     40     35
    current          500     550     600     650     750
    Total          780     830     890     970     1060
              what is the exact percentage?                    
              120/970+85/890+70/830+35/780=%     
    Here dpd is days per deliquency
    dpd are mesaures in hierarchy, and total no.of accounts in monthly wise ( here rows and columns both are hierarchys)
    ex: there are 100 accounts in the month of march for 30 dpd, and 105 accounts in the month of april for 30 dpd
    Now i want the percentage to be calculated as per the below mentioned format
    120/970+85/890+70/830+35/780=%
    here 120 is no.of accounts in july for 30dpd and 970 is total no of accounts for all days for june
    here 85 is no.of accounts in july for 30dpd and 890 is total no of accounts for all days for May
    here 70 is no.of accounts in july for 30dpd and 830 is total no of accounts for all days for april
    here 35 is no.of accounts in july for 30dpd and 780 is total no of accounts for all days for march

    There are so many things wrong with your questions that I lost my appetite to help:
    http://catb.org/esr/faqs/smart-questions.html#bespecific
    http://catb.org/esr/faqs/smart-questions.html#urgent
    http://catb.org/esr/faqs/smart-questions.html#writewell
    http://catb.org/esr/faqs/smart-questions.html#formats

  • I can no longer view source files in Firefox 6. This is very important for my job as an SEO consultant.

    Under View I can no longer read the Source files for a webpage. As an SEO consultant this is vital for my work. Please can you restore this feature for FireFox 6.

    You can also use these shortkeys:
    * Web Console -> CTRL + SHIFT + K
    * Scratchpad -> SHIFT + F4
    * View Page Source -> CTRL + U
    * Error Console -> CTRL + SHIFT + J
    Check and tell if its working.

Maybe you are looking for