Latest web development tutorials

C cycle

Sometimes, we may need to repeatedly perform the same piece of code. Under normal circumstances, the statements are executed sequentially: the first statement in the function executed first, followed by a second statement, and so on.

Programming languages ​​provide various control structures more complex execution paths.

Loops allow us to repeatedly execute a statement or group of statements, the following is the most programming languages ​​loop flow chart?:

Loop structure

Type of cycle

C language provides the following cycle types. Click on the link to view the details of each type.

循环类型描述
while 循环 当给定条件为真时,重复语句或语句组。它会在执行循环主体之前测试条件。
for 循环 多次执行一个语句序列,简化管理循环变量的代码。
do...while 循环 除了它是在循环主体结尾测试条件外,其他与 while 语句类似。
嵌套循环 您可以在 while、for 或 do..while 循环内使用一个或多个循环。

Loop control statements

Loop control statements change the order of execution of your code. Through which you can jump code.

C provides the following loop control statements. Click on the link to view the details of each statement.

控制语句描述
break 语句 终止循环switch语句,程序流将继续执行紧接着循环或 switch 的下一条语句。
continue 语句 告诉一个循环体立刻停止本次循环迭代,重新开始下次循环迭代。
goto 语句 将控制转移到被标记的语句。但是不建议在程序中使用 goto 语句。

Infinite loop

If the condition is never false, the loop becomes an infinite loop.for circulation in the traditional sense it can be used to implement an infinite loop.Since the three expressions constitute any one cycle is not required, you can be certain conditional expression blank to form an infinite loop.

#include <stdio.h>
 
int main ()
{

   for( ; ; )
   {
      printf("This loop will run forever.\n");
   }

   return 0;
}

When the conditional expression does not exist, it is assumed to be true. You can also set an initial value and the increment expression, but under normal circumstances, C programmers prefer to use for (;;) structure to represent an infinite loop.

Note: You can press Ctrl + C to terminate an infinite loop.