exiting a while loop with a negative integer

前端 未结 4 432
情话喂你
情话喂你 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 13:52

    Use an if condition to know the number is less than 0 or not. And if yes, just use break statement inside it, which will bring you out of the loop. Learn more about break statement from MSDN.

提交回复
热议问题