Explain pretest and post test loops
with syntax and an example
language
Answers
Answer:
A pretest loop tests its condition before each iteration. A posttest loop tests its condition after each iteration. A posttest loop will always execute at least once. ... Because they are only executed when a condition is true.
Answer:
A posttest loop is a type of loop in which the condition is tested after the loop body is executed. This means that the loop body will always be executed at least once.
Explanation:
From the above question,
They have given :
Posttest Loops:
A posttest loop is a type of loop in which the condition is tested after the loop body is executed. This means that the loop body will always be executed at least once. Syntax for a posttest loop in most programming languages is as follows:
do {
// loop body
} while (condition);
Example in JavaScript:
let count = 0;
do {
console.log("Count is " + count);
count++;
}
while (count < 5);
Pretest loops are more efficient because they don't waste time evaluating the condition if it's already false. However, posttest loops guarantee that the loop body will be executed at least once. It's important to consider which type of loop best fits the situation when writing code.
For more such related questions : https://brainly.in/question/54845385
#SPJ3