exiting a while loop with a negative integer

前端 未结 4 472
情话喂你
情话喂你 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条回答
  •  Happy的楠姐
    2021-01-27 13:51

    int i = -1;
    do
    {
        i = magic_user_input();
        //simple enough? get a decent programming book to get the hang of loops
    }
    while(i > -1)
    

    edit: sorry, my mistake: 'i' wasn't declared properly :) now it should be fine to use

提交回复
热议问题