Chapter 6. SwitchTask
Prev | Additional Ant Tasks | Next

## 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

Attribute | Description | Default | Required
--- | --- | --- | ---
name | The name of a property whose value will be used for the switch. | None | Yes

Table 6.2. "case" and "default" Attributes

Attribute | Description | Default | Required
--- | --- | --- | ---
value | The 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. | None | Yes

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

Prev | Up | Next
More Conditions | Home | Chapter 7. Try Task