C language special method for nested loop

This article is suitable for friends who are beginners to C language, who can’t figure out the order of the program, don’t know where to insert loops or loop nesting redundancy, and are prone to errors. If you don’t know how to write after the loop, you can use this routine as a reference.
Before talking about this method, the basic sentences of programming language, that is, machine language assembly language must realize the three basic program directions of sequence, judgment, and jump (loop) in order to realize various processes. The corresponding C language sentence is the sequence. , If statement, loop statement.
The applicable scenarios of this method: when writing a program, we don't know where to insert the loop, and where to end the loop or there are multiple nested loops, we don't know how to write.
Start talking about the method: First, turn the thought into an idea realized in assembly language, that is, only use sequence, judgment, and jump (loop) to complete the logic of the realization. We first write in order, and if we want to judge, we write the judgment condition (such as x=1), and then write a paragraph in order and encounter the judgment, when the judgment condition at this time includes the previous judgment condition (more than or equal to) (such as x=1 and Add a jump mark when y=1). At this time, try to form a loop between the two judgment statements while, the condition of while is the one with the most logic of the two judgment conditions (such as x=1 and y=1) , Now to see if this cycle meets the demand. The conditions for the end of the loop now become three (4 cases minus 1, whether x is equal to 1, two, whether y is equal to 1, two, a total of 2 times 2, 4 cases) that is x=1 and y!=1, x!=1 and y=1, x!=1 and y!=1, so the three cases must be judged separately after the loop ends, and the ones that do not need to be judged can be combined.
In the above example, some friends did not use this method. The first time they write, they may write while(x=1) and then nest while(x=1&&y=1), which is obviously wrong and redundant. Not easy to handle.

Advantages: Routines can save time and are the most streamlined when dealing with nested loops.

I named this method "strict loop processing", haha.

Guess you like

Origin blog.csdn.net/qq_41655658/article/details/108658517