In: Computer Science
What is the difference between a pretest and posttest Do...loop statement? give an example of each loop using pseudocode. A pretest is something which is checked before entering into the loop and executing loop statements.. like: while(condition is true) { // execute. } A posttest is something, which is checked after executing the loop statements.. Hence there is a gurantee that the loop statements will run atleast once.. the posttest basically determines if the loop statements should be executed again or not. do { // execute. } while(condition is true); ================== What is infinite loop, how to avoid your program runs with an endless loop? give an example using psuedocode or explanation => An infinite loop is something, whose looptest condition always remains true.. while(true) { // Print something. } A loop of above kind will keep running infinitely, and will never stop (until your system supports). To Avoid such kind of cases, We should define some end condition or break statements.. like below: while(true) { if(condition) { break; } // Print something. }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.