Categories: VB.Net Api

VB.Net 教程:If … Then语句

返回到:VB.Net – 决策

它是控制语句的最简单形式,经常用于决策和改变程序执行的控制流程。 if-then语句的语法是:

If condition Then 
[Statement(s)]
End If

其中,condition是一个布尔或关系条件,Statement(s)是一个简单或复合语句。 If-Then语句的示例是:

If (a <= 20) Then
   c= c+1
End If

如果条件的计算结果为true,那么If语句中的代码块将被执行。 如果条件计算结果为假,则第一组代码在If语句结束后(在结束If之后)将被执行。

流程图:

示例:

Module decisions
    Sub Main()
        'local variable definition 
        Dim a As Integer = 10

        ' check the boolean condition using if statement 
        If (a < 20) Then
            ' if condition is true then print the following 
            Console.WriteLine("a is less than 20")
        End If
        Console.WriteLine("value of a is : {0}", a)
        Console.ReadLine()
    End Sub
End Module

当上述代码被编译和执行时,它产生以下结果:

a is less than 20
value of a is : 10

返回到:VB.Net – 决策

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

5 天 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

2 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

2 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

3 周 ago

聊聊React和Vue组件更新的实现及区别

React 和 Vue 都是当…

4 周 ago