Explore chapters and articles related to this topic
Computer Programming
Published in Quamrul H. Mazumder, Introduction to Engineering, 2018
DO…UNTIL loops are very similar to WHILE…DO loops. The only difference is that in a WHILE…DO loop the condition must be true for the code within the loop to be executed, whereas in a DO…UNTIL loop the code in the loop is executed at least once before the condition is checked. Thus, depending on the condition that is to be satisfied, it is possible that the code in the WHILE…DO loop is never executed, and, in the DO…WHILE loop, the code will always be executed at least once.
Conditional Statements
Published in Amartya Mukherjee, Nilanjan Dey, Smart Computing with Open Source Platforms, 2019
Amartya Mukherjee, Nilanjan Dey
It is a special kind of loop often known as an exit control loop. Because the condition is checked during the time of exit of the loop, the name is so. The main property of do-while loop is that the loop will execute at least once even if the condition is not satisfied at a particular moment. The do-while loop basically ends with a semicolon, which suggests that the control is at the end of the loop, so no further statement is inside the loop in this case. An example of a do-while loop is shown as follows:
The research of endless loop detection method based on the basic path
Published in International Journal of Computers and Applications, 2020
Xuexin Gao, Yongmin Mu, Meie Shen
In the program containing the for loop statement and the while loop statement, there also is judgment nodes, that is, the exit condition of the loop. Therefore, the for statement and the while statement should also be a structure feature information in the control flow. The analysis results of the for loop structure is respectively shown in Figure 3. Since the two codes implement exact same function, the intermediate code obtained by GCC is exactly same. The do while loop structure and the while loop structure are also the same.
An iterated local search algorithm for solving large-scale instances of the duplex arrangement problem
Published in Engineering Optimization, 2023
Algorithm 3 expects a permutation π and its associated value v as input. At Line 1, the best value so far, , is set to v. At Lines 2–4, the vector Index, which contains indices to positions in the permutation π, is initialized; at Line 5 the vector Index is shuffled; at Line 6 the counter cnt is set to (because no swap has yet been accepted). Then, the algorithm enters a do–while loop (Lines 7–21) that contains two for loops (Lines 8–20). The do–while loop is used to execute the two internal for loops, while a local optimal solution has not yet been reached. The two for loops generate the sequence At Line 10, the counter cnt counts the number of pairs that are being generated. At Line 11, the value v of the permutation obtained by a swap of the elements of π at positions and is calculated. If this value is better than (Line 12), then the swap is performed, is updated and cnt is set to zero (Lines 13–15). Note that cnt is set to zero because, after the first swap has been accepted, the intention is to terminate the search after swap moves have failed to be accepted. One is subtracted from the total number of swaps () because the latest swap accepted should not be tried again—because it would revert the current permutation back to the (worse) previous one, and thus it would not be accepted anyway. At Line 16, if cnt equals , i.e. all necessary swaps have been tried but failed, then the current permutation π and best solution value so far are returned.