Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21
  1. #11

    In addition, a while or do-while loop can lead to an infinite loop while a "for" loop cannot as long as you have specified the condition and increment.

    syntax:

    Code:
    for(initializer; condition; increment)
    while(condition)
    do {} while(condition)
    Example below can lead to an infinite loop

    Code:
    int i = 0;
    while (i < 5)
    {
           printf("%d\n", i);
           continue;
           ++i;
    }
    or

    Code:
    do
    {
           printf("%d\n", i);
           continue;
           ++i;
    } while (i < 5);
    while below won't

    Code:
    for (int i = 0; i < 5; ++i)
    {
          continue;
          ++i;
    }
    except if you leave the increment blank like
    Code:
    for (int i = 0; i < 5;)
    {
          continue;
          ++i;
    }
    then it will lead to an infinite loop.

    if-else versus a switch statements are the same except that some programming languages won't let you use switch statements on certain data types. "switch" is more readable if you need to perform a lot of checks so use it in those situations.

  2. #12
    Quote Originally Posted by -_- View Post
    unsa pasabot nimo na mo ungot ka? mo ungot imo program?
    i mean maungot ko ana nga conditions.
    maglibog ko asa nana sya ibutang sa ako program.
    not the computer nga muongot

  3. #13
    kung moongot jud bai... morag dili jud nimo field ang programming.. pag police nalang!!! lols

  4. #14
    Quote Originally Posted by reyarita View Post
    i mean maungot ko ana nga conditions.
    maglibog ko asa nana sya ibutang sa ako program.
    not the computer nga muongot
    ang purpose ana nila pang redirect sa flow of control
    basically ang flow sa program is top to bottom kung wala ka ana and walay mga functions,
    so if naa kay ganahan na part na dili agian then gamit ka ug conditions like IF
    pero kung ganahan kag magbalik balik then use the loops FOR, WHILE, DO WHILE

    murag ing ana ang rationale

    generally considered "Flow of control", or control the flow

  5. #15
    before ka mag program dapat mag tuon sa ka og flow charting ^_^
    it really helps to sort things out

  6. #16
    I'll show off something, how nifty you can do something nice.
    Code:
    while()
    {
            if(){
                   for(;;)
                   {
                   }
            }
            else{
                   if(){
                             while(){
                                   switch()
                                   {
                                           case :  break;
                                           case :  break;
                                           default:
                                   }
                             }
                   }
            }
    }

    whatever it is..... it's a vital piece of command, don't take it lightly. Grasp the potential of your everycode, anything can happen based on your design and algorithm skills.

  7. #17
    Quote Originally Posted by junkfactory View Post
    Example below can lead to an infinite loop

    Code:
    int i = 0;
    while (i < 5)
    {
           printf("%d\n", i);
           continue;
           ++i;
    }
    or

    Code:
    do
    {
           printf("%d\n", i);
           continue;
           ++i;
    } while (i < 5);
    Well that's because the continue statement ignores the rest of the code (that's within the body of the current loop) after it and then continues the loop. Which means that the ++i line isn't executed. It's NOT the fault of the loop but the fault of the order of the statements.

    If you have an infinite loop even if you have the correct condition, then that generally means that you're doing something wrong inside the body of your loop. Which in this case is not incrementing the counter before the continue statement.
    Last edited by doomsweek; 11-24-2009 at 10:56 PM.

  8. #18
    Quote Originally Posted by doomsweek View Post
    Well that's because the continue statement ignores the rest of the code (that's within the body of the current loop) after it and then continues the loop. Which means that the ++i line isn't executed. It's NOT the fault of the loop but the fault of the order of the statements.

    If you have an infinite loop even if you have the correct condition, then that generally means that you're doing something wrong inside the body of your loop. Which in this case is not incrementing the counter before the continue statement.
    Mga in-ana na erroneous statements gi-check naman na sa mga modern compiler. For example sa Java, it will have a compile error message na "Unreachable code".

  9. #19
    Ah bitaw sah. Pero murag warning ra raman tingali to.

  10. #20
    Quote Originally Posted by silent-kill View Post
    after all have been said here, all i can say is use your imagination and common sense lol.
    Nyati ra..... fu fu fu! peace bro.....
    *** sense of your code oi....

  11.    Advertisement

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

 
  1. Ten Reasons to use SAP 2500 for your Water Station Business
    By ingenmart in forum Business, Finance & Economics Discussions
    Replies: 1
    Last Post: 02-23-2012, 09:50 PM
  2. For Sale: im selling my CPU unit good as set ready to use...see inside for details...
    By dookie3283 in forum Computers & Accessories
    Replies: 17
    Last Post: 09-02-2011, 04:19 AM
  3. For Sale: rush for to night if mada for only 25k
    By sexy_back in forum Computers & Accessories
    Replies: 1
    Last Post: 05-04-2011, 09:01 PM
  4. how to use a methods in a switch case? I need it so badly
    By istoryansucks in forum Programming
    Replies: 11
    Last Post: 07-19-2010, 04:41 PM
  5. Replies: 14
    Last Post: 10-07-2005, 04:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top