if ... then
if ... then ...;这里加分号不加分号有什么区别
else
end多重嵌套条件中的;是什么规则
if ... then ...;这里加分号不加分号有什么区别
else
end多重嵌套条件中的;是什么规则
解决方案 »
- Delphi字符串操作问题
- 有做过用友ERP二次开发的朋友过来看看啊。。。
- 北京天地纵横软件有限公司诚聘Delphi程序开发人员
- 使用activex控件的程序,用户安装时,有什么特别要求,必须注册activex控件吗?
- 一个不用建立在别的WEB服务器(IIS等)上的WEB程序
- Emergency!!!!各位大虾救我!关于查询窗体直接转换为报表问题!!在线等待!
- 程序中响应F1-F12键
- 求教:关于BDE连接Oracle9i的问题!
- delphi客户端登录服务器出错处理
- 哥们儿帮忙进去看看里面的程序错在哪儿?谢了
- 请问如何将xls文件的int类型保存到 sql server表的int字段中?
- 为什么老说我的窗口没定义呀,晕
Case语句结构语句:概述 编者注要避免嵌套if语句产生歧义(明确地说,就是编写代码或阅读代码时人的理解与编译器根据规则作出的解析之间有偏差),可以通过尽量用if…then...else语句代替if...then...语句实现。(或者根据情况使用case语句,相关信息见Case语句中的编者注。)下面的两个例子就清楚地表达了代码的逻辑: 例子一:if A then begin P1;end else begin if B then begin P2; end else begin P3; end;end; 例子二:if A then begin if B then begin P1; end else begin P2; end;end else begin P3;end; 从上面两个例子可以看出,编写代码时,文本布局的风格也会影响到代码的可读性。例如,下面的语句读起来就比较费劲: if A then begin P1;endelsebeginif B then begin P2;endelsebegin P3;end;end; 尽管这里的代码与“例子一”的程序逻辑是一致的。
若条件不成立 这时候做什么就相当于
if then else
showmessage('1') //这里必须没分号
else
showmessage('2');也可写成
if true then
begin
showmessage('1'); //这里必须有分号
end //这里没分号
else
showmessage('2');就这样了.
begin
end else
begin
end;
喝尿尿
else
喝酒;
if ... then ...;这里加分号不加分号有什么区别
else
end多重嵌套条件中的;是什么规则
--
加分号,则编译错误;不加,则正确,下面else此应此if
else
Result := I/J;The then and else clauses contain one statement each, but it can be a structured statement. For example,if J <> 0 thenbegin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;Notice that there is never a semicolon between the then clause and the word else. You can place a semicolon after an entire if statement to separate it from the next statement in its block, but the then and else clauses require nothing more than a space or carriage return between them. Placing a semicolon immediately before else (in an if statement) is a common programming error.
A special difficulty arises in connection with nested if statements. The problem arises because some if statements have else clauses while others do not, but the syntax for the two kinds of statement is otherwise the same. In a series of nested conditionals where there are fewer else clauses than if statements, it may not seem clear which else clauses are bound to which ifs. Consider a statement of the formif expression1 then if expression2 then statement1 else statement2;There would appear to be two ways to parse this:if expression1 then [ if expression2 then statement1 else statement2 ];
if expression1 then [ if expression2 then statement1 ] else statement2;The compiler always parses in the first way. That is, in real code, the statementif ... { expression1 } then if ... { expression2 } then
... { statement1 }
else
... { statement2 } ;is equivalent toif ... { expression1 } thenbegin
if ... { expression2 } then
... { statement1 }
else
... { statement2 }
end;The rule is that nested conditionals are parsed starting from the innermost conditional, with each else bound to the nearest available if on its left. To force the compiler to read our example in the second way, you would have to write it explicitly asif ... { expression1 } thenbegin
if ... { expression2 } then
... { statement1 }
end
else
... { statement2 } ;
if ... then
if ... then ...;这里加分号不加分号有什么区别
else
加表示下面的else 跟外面层的if
不加表法跟里面层的if
if then else 是一个整体,就近匹配原则,ok ,over