Tcl If 语句

Tcl If 语句

if 语句由布尔表达式后跟一个或多个语句组成。

语法

在Tcl语言中,’if’语句的语法如下所示-

if {boolean_expression} {
   # statement(s) will execute if the Boolean expression is true
}
Bash

如果布尔表达式的值为 true ,那么在 if 语句内的代码块将被执行。如果布尔表达式的值为 false ,那么在’if’语句结束后(即右花括号之后)的第一组代码将被执行。

Tcl语言在内部使用 expr 命令,所以我们不需要显式使用 expr 语句。

流程图

Tcl If 语句

示例

#!/usr/bin/tclsh

set a 10

#check the boolean condition using if statement
if { a<20 } {
   # if condition is true then print the following   puts "a is less than 20" 
}
puts "value of a is :a"
Bash

当上面的代码被编译和执行时,它产生以下结果−

a is less than 20
value of a is : 10
Bash

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程