- Tcl Tutorial
- Tcl - Home
- Tcl - Overview
- Tcl - Environment Setup
- Tcl - Special Variables
- Tcl - Basic Syntax
- Tcl - Commands
- Tcl - Data Types
- Tcl - Variables
- Tcl - Operators
- Tcl - Decisions
- Tcl - Loops
- Tcl - Arrays
- Tcl - Strings
- Tcl - Lists
- Tcl - Dictionary
- Tcl - Procedures
- Tcl - Packages
- Tcl - Namespaces
- Tcl - File I/O
- Tcl - Error Handling
- Tcl - Built-in Functions
- Tcl - Regular Expressions
- Tk Tutorial
- Tk - Overview
- Tk - Environment
- Tk - Special Variables
- Tk - Widgets Overview
- Tk - Basic Widgets
- Tk - Layout Widgets
- Tk - Selection Widgets
- Tk - Canvas Widgets
- Tk - Mega Widgets
- Tk - Fonts
- Tk - Images
- Tk - Events
- Tk - Windows Manager
- Tk - Geometry Manager
- Tcl/Tk Useful Resources
- Tcl/Tk - Quick Guide
- Tcl/Tk - Useful Resources
- Tcl/Tk - Discussion
Tcl - Nested Switch Statement
It is possible to have a switch as part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.
Syntax
The syntax for a nested switch statement is as follows −
switch switchingString { matchString1 { body1 switch switchingString { matchString1 { body1 } matchString2 { body2 } ... matchStringn { bodyn } } } matchString2 { body2 } ... matchStringn { bodyn } }
Example
#!/usr/bin/tclsh set a 100 set b 200 switch $a { 100 { puts "This is part of outer switch" switch $b { 200 { puts "This is part of inner switch!" } } } } puts "Exact value of a is : $a" puts "Exact value of a is : $b"
When the above code is compiled and executed, it produces the following result −
This is part of outer switch This is part of inner switch! Exact value of a is : 100 Exact value of a is : 200
tcl_decisions.htm
Advertisements