Recent Post

Example 3: Pattern Generation

Pattern 1:
#!/usr/bin/tclsh

for {set i 1} {$i <= 5} {incr i} {
	for {set j 1} {$j <= $i} {incr j} {
		puts -nonewline $i
	}
puts ""
}
Output:
1
22
333
4444
55555
Pattern 2:
#!/usr/bin/tclsh

for {set i 1} {$i <= 5} {incr i 2} {
	for {set j 1} {$j <= $i} {incr j 1} {
		puts -nonewline [ format "%-2s" * ]
	}
	puts " "
}

for {set i 1} {$i <= 5} {incr i 2} {
	for {set j 4} {$j > $i} {incr j -1} {
		puts -nonewline [ format "%-2s" * ]
	}
	puts " "
}
Output:
*
* * *
* * * * *
* * *
*

Comments