void main()
{
char ch = 'A';
while (ch <= 'F')
{
switch (ch)
{
case 'A':
case 'B':
case 'C':
case 'D':
ch++;
continue;
case 'E':
case 'F':
ch++;
}
putchar (ch);
}
}
我的问题是为什么即使while循环的条件小于'F',上述代码也只打印FG。为什么不打印其他角色。
答案 0 :(得分:1)
从A
到D
,while循环继续,即每当点击继续时,它会返回到顶部while (condition)
当char为E
时,它会递增ch
,而ch
现在F
正在放置o / p。
现在,char处于F
状态,并且它会在交换机中ch
递增,而ch
有G
,并且会将其放在控制台上。
因此o / p为FG
值得注意的是,如果continue
是其中一个字符ch
,A
,B
或C
,D
语句将会执行因为如果没有陈述,开关案件就会失败
答案 1 :(得分:1)
Public Function ExtractParenthesis(strText As String) As Collection
Dim i As Long
Dim RegExp As Object
Dim Matches As Object
Dim Output As New Collection
Set Output = Nothing
Set RegExp = CreateObject("vbscript.regexp")
RegExp.Pattern = "{(.*?)}"
RegExp.Global = True
Set Matches = RegExp.Execute(strText)
For i = 0 To (Matches.count - 1)
Output.Add Matches(i).submatches(0)
Next i
Set ExtractParenthesis = Output
End Function
中断循环并从头开始下一次迭代。
你的循环等同于
continue
答案 2 :(得分:0)
您的代码在递增和打印后检查是否ch > 'F'
,换句话说,当打印ch = 'G'
时,条件变为false并且循环终止。
至于为什么不打印其他字符,当ch <= D
递增而continue
导致它跳过putchar
并跳回while
时}语句来。
编辑:显然预期的输出为ABCEF
。请注意,如果没有break
- 语句,switch-case
只会继续下一个案例。 ch
的值确定代码在什么情况下开始执行,但除非它找到break
语句,否则它将直到下一个案例。