Thread: best way to brake a while(TRUE) loop?

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    28

    best way to brake a while(TRUE) loop?

    I have a while(TRUE) loop that I need to break...Only way I can think to do this is with a if then goto. I know that is poor programming. What is the best way to brake this loop?

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Use a break; statement?

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    28
    Thats clownin...lol, I guess I've been at it tooo long...just not thinking. Boy, I feel dumb as ....
    thanks

  4. #4
    Registered User
    Join Date
    Apr 2004
    Posts
    42
    Use goto!

  5. #5
    Awesomefaceradcore bivhitscar's Avatar
    Join Date
    Apr 2006
    Location
    Melbourne, Australia
    Posts
    210
    >Use goto!

    That was sarcasm right... right!?
    it's ironic considerate rarity patron of love higher knowledge engulfs me...

  6. #6
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    there is nothing wrong with goto. Jeez

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Depending on how heavy the loop is, you may need anywhere from 8 to 25 gallons of brake fluid. To break a loop, curl both ends around your hands and pull hard in opposite directions. For larger loops you may want to invest in a knife, chainsaw or intergalactic proton blaster, depending on your budget.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 10:21 PM
  3. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 02:14 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM