Difference between “while” loop and “do while” loop

前端 未结 16 1104
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 06:44

What is the difference between while loop and do while loop. I used to think both are completely same.Then I came across following piece of code:

do {
                


        
16条回答
  •  再見小時候
    2020-12-13 07:31

    The do while loop executes the content of the loop once before checking the condition of the while.

    Whereas a while loop will check the condition first before executing the content.

    In this case you are waiting for user input with scanf(), which will never execute in the while loop as wdlen is not initialized and may just contain a garbage value which may be greater than 2.

提交回复
热议问题