📄 m2_while.hlp
字号:
{smcl}
{* 18mar2005}{...}
{cmd:help m2 while}
{hline}
{* index while tt}{...}
{title:Title}
{p 4 4 2}
{bf:[M-2] while -- while (exp) stmt}
{title:Syntax}
{cmd:while (}{it:exp}{cmd:)} {it:stmt}
{cmd:while (}{it:exp}{cmd:) {c -(}}
{it:stmts}
{cmd:{c )-}}
{p 4 4 2}
where {it:exp} must evaluate to a real scalar.
{title:Description}
{p 4 4 2}
{cmd:while} executes {it:stmt} or {it:stmts} zero or more times. The loop
continues as long as {it:exp} is not equal to zero.
{title:Remarks}
{p 4 4 2}
To understand {cmd:while}, enter the following program
{cmd}function example(n)
{
i = 1
while (i<=n) {
printf("i=%g\n", i)
i++
}
printf("done\n")
}{txt}
{p 4 4 2}
and run {cmd:example(3)}, {cmd:example(2)}, {cmd:example(1)},
{cmd:example(0)}, and {cmd:example(-1)}.
{p 4 4 2}
One common use of {cmd:while} is to loop until convergence:
{cmd}while (mreldif(a, lasta)>1e-10) {
lasta = a
a = {txt}...
{cmd:{c )-}}
{title:Also see}
{p 4 13 2}
Manual: {hi:[M-2] while}
{p 4 13 2}
Online: help for
{bf:{help m2_semicolons:[M-2] semicolons}},
{bf:{help m2_do:[M-2] do}},
{bf:{help m2_for:[M-2] for}},
{bf:{help m2_break:[M-2] break}},
{bf:{help m2_continue:[M-2] continue}};
{bf:{help m2_intro:[M-2] intro}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -