zoukankan      html  css  js  c++  java
  • if 条件语句

    //if 条件语句 
    条件语句通过条件检测,判断是否执行该条件语句中包含的语句。
    条件语句可有两种基本形式:if语句和case语句。

    If语句
    if-then型语句,仅当条件满足时,语句才执行;
    if-then-else型,if语句在两条语句中选择一条执行。

    procedure TForm1.Button1Click(Sender: TObject);
    begin
        // simple if statement
        if CheckBox1.Checked then
        ShowMessage ('CheckBox1 is checked')
    end;

    如果点击按钮后没有反应,表明复选框未被选中。
    对于这种情况,最好能交代得更清楚些,为此在第二个按钮的代码中,我用了if-then-else 语句:

    procedure TForm1.Button2Click(Sender: TObject);
    begin
        // if-then-else statement
        if CheckBox2.Checked then
            ShowMessage ('CheckBox2 is checked')
        else
            ShowMessage ('CheckBox2 is NOT checked');
    end;

    要注意的是,不能在第一句之后、else 关键词之前加分号,否则编译器将告知语法错误。
    实际上,if-then-else 语句是单纯的一条语句,因此不能在语句中间加分号。




  • 相关阅读:
    (16)C#继承
    (3)新概念英语一(11-20)lessons
    (15)C#集合
    (14)编码
    (2)新概念英语一(1-10)lessons
    (13)C#数组和元组
    Uva 11729 Commando War
    Uva 11292 Dragon of Loowater
    谈谈单元最短路
    [USACO 3.3.1]骑马修栅栏t
  • 原文地址:https://www.cnblogs.com/xe2011/p/2532899.html
Copyright © 2011-2022 走看看