概述
C Construct
num_iter = 1;
do {
flag = func();
num_iter++;
}
while (flag && num_iter <= 100)
Modeling Pattern for Do While Loop: While Iterator Subsystem block
One method for creating a do while loop is to use a While Iterator Subsystem block from the Simulink > Ports and Subsystems library.
1. Open example model ex_do_while_loop_SL.
The model contains a While Iterator Subsystem block that repeats execution of the contents of the subsystem during a simulation time step.
Observe the following settings in the While Iterator Subsystem:
The func subsystem block has an output flag of 0 or 1 depending on the result of the algorithm in func( ). func() is the Function name in func subsystem.
For the While Iterator block, the Maximum number of iterations is 100.
For the While Iterator block, the While loop type is do-while.
2. To build the model and generate code, press Ctrl+B.
The code implementing the do while loop is in the ex_do_while_loop_SL_step function in ex_do_while_loop_SL.c:
/* Model step function */
void ex_do_while_loop_SL_step(void)
{
int32_T s1_iter;
/* Outputs for Iterator SubSystem: '/While Iterator Subsystem' incorporates:
* WhileIterator: '/While Iterator'
*/
s1_iter = 1;
/* SystemReset for Atomic SubSystem: '/func' */
func_Reset();
/* End of SystemReset for SubSystem: '/func' */
/* End of Outputs for SubSystem: '/While Iterator Subsystem' */
do {
func();
s1_iter++;
} while (flag && (s1_iter <= 100));
}
Modeling Pattern for Do While Loop: Stateflow Chart
1. Open example model ex_do_while_loop_SF.
In the model, the ex_do_while_loop_SF/Chart executes the do while loop.
The chart contains a While loop decision pattern that you add by selecting Chart > Add Pattern in Chart > Loop > While.
2. To build the model and generate code, press Ctrl+B.
The code implementing the do while loop is in the ex_do_while_loop_SF_step function in ex_do_while_loop_SF.c:
/* Model step function */
void ex_do_while_loop_SF_step(void)
{
int32_T num_iter;
/* Chart: '/Chart' */
num_iter = 1;
do {
func();
num_iter++;
} while (flag && (num_iter <= 100));
}
最后
以上就是健壮砖头为你收集整理的matlab do while,Do While Loop的全部内容,希望文章能够帮你解决matlab do while,Do While Loop所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复