delphi - 仅当在 if then 中满足条件时才检查条件
问题描述
我有一个代码示例,但不确定最好使用哪种方式。
例如我有
if (x = 1) and (y = 2) and (if abc = false then check if z = 3) then
begin
...
只检查
if x = 1
if y = 2
if abc = false check z = 3. if abc = true then dont check z = 3
我不确定我是否解释得最好,但希望人们能理解。
我想知道这是否可行或最好的方法。请记住,而不是示例中的 x、y、z 和 abc。我可以使用更多。
我目前的结构...我认为这不实用,并认为有更好的方法,但我不确定
if (abc = false) then
begin
if (x = 1) and (y = 2) and (z = 3) then
begin
...
end
else
begin
if (x = 1) and (y = 2) then
begin
...
提前致谢
解决方案
您的代码示例都无法编译,因为它们都没有使用正确的语法。
这应该让你开始:
if (x = 1) and (y = 2) then
begin
if (abc) then
// Handle abc = True
else
begin
if (z = 3) then
// Handle abc = false and z = 3
else
// Handle abc = false and z <> 3
end;
end;
推荐阅读
- java - 使 try catch 语句识别各种错误
- sharepoint - 如何根据另一列自动填充列
- node.js - 在牧场主上使用 seneca 网格
- java - 在 Eclipse 中运行 JUnit 测试用例时没有可用的套接字错误
- java - Cumulocity Java 代理凭据 - 更新 MO 时拒绝访问
- r - ggplot2中的详细轴和图例
- python - Cython Numpy 数组操作比 Python 慢
- powershell - 不能使用非字符串的 TFS/VSTS 自定义变量
- c++ - 将字符串变量从 bash 脚本传递到根宏
- hibernate - 没有名为“我的 PU 名称”的 EntityManager 的持久性提供程序