Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about the use of "continue" 1

Status
Not open for further replies.

chopstick

Programmer
Apr 9, 2006
8
SG
I have writen this code here:
Code:
while (ch=getchar()!=EOF)
  {
        if(ch=='\n'||ch==' ')
        continue;
        else
        {
            counter1=0;
            while(counter1<=1000)
            {
            counter=0;
            while(counter<=1000000)
            {
                                counter++;
                                }
                                counter1++;
                                
                                }
                                printf("\a");
                                
        count++;
        }
        }
as I know, continue will bring me to the next cycle of the most outer while loop. But I can still hear the beep sound after pressing "enter", counld someone help?
 
add ch=='\r' to your list of conditions
 
Precedence and order evaluation - a classic C programmer's error. Must be:
Code:
while ((ch=getchar())!=EOF)
...
You get 1 (true) in ch, not a char from a console...
 
You should indent your code, that's difficult to read without identation.

Furthermore, the continue and else are redundant just one of them will offer the functionality you're looking for.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top