0% found this document useful (0 votes)
67 views2 pages

TCL Decisions: If Statement

Tcl Decisions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

TCL Decisions: If Statement

Tcl Decisions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

9/23/2016

TclDecisions

TclDecisions
https://www.tutorialspoint.com/tcltk/tcl_decisions.htm
Copyrighttutorialspoint.com
Decisionmakingstructuresrequirethattheprogrammerspecifiesoneormoreconditionstobeevaluatedor
testedbytheprogram,alongwithastatementorstatementstobeexecutediftheconditionisdeterminedtobe
true,andoptionally,otherstatementstobeexecutediftheconditionisdeterminedtobefalse.
Followingisthegeneralformofatypicaldecisionmakingstructurefoundinmostoftheprogramming
languages

Tcllanguageusestheexprcommandinternallyandhenceitsnotrequiredforustouseexprstatement
explicitly.
Tcllanguageprovidesfollowingtypesofdecisionmakingstatements
S.No.

Statement&Description
ifstatement

An'if'statementconsistsofaBooleanexpressionfollowedbyoneormorestatements.
if...elsestatement

An'if'statementcanbefollowedbyanoptional'else'statement,whichexecuteswhentheBoolean
expressionisfalse.
nestedifstatements

Youcanuseone'if'or'elseif'statementinsideanother'if'or'elseif'statement(s).

https://www.tutorialspoint.com/cgibin/printpage.cgi

1/2

9/23/2016

TclDecisions

switchstatement
4

Aswitchstatementallowsavariabletobetestedforequalityagainstalistofvalues.
nestedswitchstatements

Youcanuseoneswitchstatementinsideanotherswitchstatement(s).

The?:Operator
Wehavecoveredconditionaloperator?:inpreviouschapter,whichcanbeusedtoreplaceif...elsestatements.
Ithasthefollowinggeneralform
Exp1?Exp2:Exp3;

WhereExp1,Exp2,andExp3areexpressions.Noticetheuseandplacementofthecolon.
Thevalueofa'?expression'isdeterminedlikethis:Exp1isevaluated.Ifitistrue,thenExp2isevaluatedand
becomesthevalueoftheentire'?expression.'IfExp1isfalse,thenExp3isevaluatedanditsvaluebecomesthe
valueoftheexpression.Anexampleisshownbelow.
#!/usr/bin/tclsh
seta10;
setb[expr$a==1?20:30]
puts"Valueofbis$b\n"
setb[expr$a==10?20:30]
puts"Valueofbis$b\n"

Whenyoucompileandexecutetheaboveprogram,itproducesthefollowingresult
Valueofbis30
Valueofbis20

https://www.tutorialspoint.com/cgibin/printpage.cgi

2/2

You might also like