Do-While Loop
Not Started

The do-while loop is another type of loop. It is useful in situations where you need to perform an action at least once, regardless of whether a certain condition is met:

someAction(); while(someCondition == true) { someAction(); }

To ensure that someAction() is executed at least once and possibly multiple times based on someCondition, we can use the do-while loop instead of calling someAction() twice and repeating ourselves.

do { someAction(); } while(someCondition == true);

In a do-while loop, we specify the action that needs to be repeated in the do block. This block is executed at least once, irrespective of the condition. The subsequent executions of the block only occur when the condition is true.

While this difference may seem small, it can impact readability significantly when the action to be repeated is lengthy, spanning across several lines or methods. Using a do-while loop in such cases can make the code more concise and readable, avoiding the need to repeat the code twice.

Challenge

Let's try the same challenge as before with a do-while loop instead.

Currently, the handleCallout() method only calls the sendCallout() method once and returns the response.

sendCallout() sometimes returns failed but the team has noticed that retrying the callout a few times eventually leads to a success.

To ensure a successful response, update the code to repeatedly call the sendCallout() method using a do-while loop until a response other than failed is received.