asp.net if else條件陳述式的使用方法(vb.net)

來源:互聯網
上載者:User

If條件式中的語句塊也是一組if條件式,其語句塊又為一組if條件

式,如此重複下去直到條件設定完畢。

  一般而言,最複雜的條件式為嵌套條件式語句,以上所提到的

所有條件式語句格式都可以形成嵌套條件式語句,只要文法概念清

if then

<script runat="server">
   sub Page_Load(Sender as object, e as eventargs)
      dim MyMessage As String = "Hello"
      dim MyBool As Boolean = True

      if MyMessage = "Hello" then
         Response.Write("True")
      end if

      if MyBool then
         Response.Write("True")
      end if  
   end sub  
</script>

下面來個複雜的語句

If條件式1 Then
  If條件式2 Then
  語句塊1
Else
  語句塊1—2
  End I f
  其他語句
Else
  語句塊2
End If

簡單一實例

<%@ Page Language="C#" %>

<script runat="server">
   void Page_Load(Object Sender, EventArgs e) {
      string MyMessage = "Hello";
      bool MyBool = true;
  
      if (MyMessage == "Hi" & MyBool) {
         Response.Write(MyMessage);
      } else if (MyMessage == "Hello") {
         Response.Write("True");
      } else {
         Response.Write("False");
      }

      if (!MyBool) {
         Response.Write("False");
      }  
   }
</script>

<html><body>

</body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.