[The fourth sword of c language (berak; the difference between continue)]

The fourth sword of c language (berak; the difference between continue)

1.
In the loop defined by berak in C language, the break statement can also be used to jump out of the current loop structure immediately after executing a branch. In the process of debugging some programs, break is used to set breakpoints.

2. Self-understanding
From the above meaning, we can understand that the function of break is to jump out of the current cycle, so what kind of existence does it look like in actual operation? Please see the figure below. The function of
insert image description here
this cycle is to print the number from 0 to 10.
insert image description hereThis is the running result .

What happens when we add the break function?

insert image description here
Added a for loop, which added a break function
insert image description here

We know from the running results that break skips the number after printing 4, and directly ends the running forcibly.

It can be seen from this that break will jump out of this cycle when the condition is met, but please pay attention

break can only skip one layer of loops, but not loops within loops

2.continue

The official definition of continue is

Skip the remaining unexecuted statements in the current loop body, and immediately proceed to the next loop condition judgment, which can be understood as only ending the current loop.

Note: The continue statement does not terminate the entire loop.
Please see the picture below

insert image description here

In the running results, we can see that after the condition of continue is satisfied, continue directly skips this cycle and enters the next cycle, so 5 is not printed during the operation; this is also the difference from berak.

The above is my initial understanding of break;continue. If there are any deficiencies, please criticize and correct me. As an apprentice who is just learning C language, I will maintain a humble and studious attitude. Thank you for all the big brothers who criticized and corrected me. And thanks one by one!

Guess you like

Origin blog.csdn.net/nanmiao666/article/details/130188094