在一个循环语句内,为什么alert输出内容能显示,而document.write不显示。

这是一段计算输入任意年月,得出相应月数天数的代码。
当输出代码改成document.write()时页面不显示,直接进行下一次循环。
我换成alert()则有显示弹窗。
想知道为什么document.write()不显示。

```javascript

<script>
    // 当输入完成并得出结果后,循环该代码,以便进行下一次输入
    while (true) {
      // 输入两个数据并装存
      const year = +prompt('请输入年份:')
      const month = +prompt('请输入月份:')
      // 判断是否为闰年的二月
      if (month === 2) {
        // 闰年二月29if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
          // document.write('29天')
          alert('29天')
          // break
          // 平年二月28天
        } else {
          // document.write('28天')
          alert('28天')
          // break
        }
        // 输入其他月份则区分大小月
      } else {
        // 大月31// alert(1)
        switch (month) {
          case 1:
          case 3:
          case 5:
          case 7:
          case 8:
          case 10:
          case 12:
            // document.write('31天')
            alert('31天')
            // alert(2)
            break
            // 小月30天
          case 4:
          case 6:
          case 9:
          case 11:
            // document.write('30天')   /为什么document不显示,而alert能显示?
            alert('30天')
            break
            // 输入不正确的月份弹出警告
          default:
            alert('输入的月份不正确!')
            break
        }
      }
    } 
  </script>

```

prompt和alert是会阻塞进程的,当遇到他们的时候程序就会暂停

所以当document.write执行的时候,还没渲染就被下一次循环的prompt给阻塞进程了,document.write的渲染自然也暂停了