Pertanyaan

8. A post-test loop evaluates its condition at the end of the loop instead of the beginning. True False 4. A pre-test loop evaluates the condition prior to execution of the loop True or False? True False 5. A while loop is often used with Scanner input as you don't know many times you'll need to re -prompt the user if they type bad data. True False

Solusi

Terverifikasi Ahli
4.7 (217 Suara)
Chetan ahli ยท Tutor selama 3 tahun

Jawaban

**8. A post-test loop evaluates its condition at the end of the loop instead of the beginning.****True****Explanation:**A post-test loop, such as a `do-while` loop, evaluates its condition after the loop has executed at least once. This means the body of the loop will always execute at least once, regardless of whether the condition is true or false.**4. A pre-test loop evaluates the condition prior to execution of the loop****True****Explanation:**A pre-test loop, such as a `while` or `for` loop, evaluates its condition before executing the loop's body. If the condition is true, the loop will execute; if it is false, the loop will terminate immediately.**5. A while loop is often used with Scanner input as you don't know many times you'll need to re-prompt the user if they type bad data.****True****Explanation:**A `while` loop is suitable for situations where you need to repeatedly prompt the user for input until valid data is provided. Since you don't know in advance how many attempts it will take to get valid input, a `while` loop allows the program to continue looping until the condition (e.g., valid input) is met.