help on switch command

hi

can anybody help me with the switch syntax?

set exam(AAA BBB CCC)
foreach ii ($exam)
switch ($ii)
case $ii=="AAA"
echo aaa
breaksw
case $ii=="BBB"
echo bbb
breaksw
case $ii=="CCC"
echo ccc
endsw
end

I couldnt print out aaa.bbb and ccc as I want on screen. I guess it might be the problem of switch syntax. Can anyone help me?

try:

#! /usr/bin/csh

set exam=(AAA BBB CCC)
foreach ii ($exam)
        switch ($ii)
        case "AAA"
                echo aaa
        breaksw
        case "BBB"
                echo bbb
        breaksw
        case "CCC"
                echo ccc
        endsw
end

if I have 2 nested foreach loop and I have two conditions to satisfy in switch case, how should I correct the syntax below to the correct one?

#! /usr/bin/csh

set exam=(AAA BBB CCC)
set son=(aa bb cc)
foreach ii ($exam)
foreach jj ($son)
switch ($ii $jj)
case "AAA"&&"aa"
echo aaa
breaksw
default
echo BBB CCC
endsw
end
end

You can only use a single variable in a switch. But you could make it a combined variable:

#! /usr/bin/csh

set exam=(AAA BBB CCC)
set son=(aa bb cc)
foreach ii ($exam)
        foreach jj ($son)
                set result="${ii}${jj}"
                switch ($result)
                case "AAAaa"
                        echo aaa
                breaksw
                default
                        echo BBB CCC
                 endsw
        end
end