exiting a while loop with a negative integer

前端 未结 4 436
情话喂你
情话喂你 2021-01-27 13:15

I want to exit a while() when the user enters a negative number of any size. What kind of condition would I need at the start of the loop to get the loop to exit w

4条回答
  •  故里飘歌
    2021-01-27 14:10

    Do not define your variable as unsigned variable. As suggested in other answers use if statement and break with if statement.

    example:

    int main(void)
    {
     int i;
     while(1){
     /*here write an statement to get and store value in i*/ 
      if(i<0)
      {
        break;
      }
     /*other statements*/
      return(0);
      }
     } 
    

提交回复
热议问题