Chapter 6. SwitchTask

The "Switch" task works much like the Java "switch" construct. It supports nested "case" elements, which in turn, support nested "break" elements. There is also a "default" case element, so this should be very natural for Java developers to use.

Table 6.1. Switch Task Attributes

nameThe name of a property whose value will be used for the switch.NoneYes

Table 6.2. "case" and "default" Attributes

valueThe value of of the property used for the switch. If this value equals the property value, then all tasks in this 'case' will be executed.NoneYes

<property name="foo" value="bar"/>
<switch name="foo">
    <case value="baz">
        <echo>Executing case baz</echo>
    <case value="bar">
        <echo>Executing case bar</echo>
        <if name="foo" value="bar">
            <echo>breaking from the if</echo>
        <echo>Falling through to case "bat"</echo>
    <case value="bat">
        <echo>Executing case bat</echo>
        <echo>Executing default case</echo>