Official Content

Performs a set of commands depending on the condition.

Syntax

Do Case
    Case condition1
        CodeBlock1
    Case conditionN
        CodeBlockN
    Otherwise
        OtherwiseCodeBlock
Endcase

Where:

condition1
   Condition1 evaluated.

CodeBlock1
   Code block that is executed if condition1 evaluates to true.

conditionN
   ConditionN evaluated.

CodeBlockN
   Code block that is executed if conditionN evaluates to true.

Otherwise
    Clause that establishes a final alternative, in case all previous conditions are not matched.

OtherwiseCodeBlock
    Block that is executed if all previous conditions are not matched (evaluated false).

Scope

Objects: Procedure, Web Panel, PanelTransaction
Generators: .NET.NET FrameworkJavaAngular,  Android, Apple

Description

This command works in the same way as if/else. It performs a set of commands within cases depending on conditions, which can involve attributes and/or variables.

When the first Case whose condition is satisfied is executed, it prevents the others from being executed. 

The statements specified under the Otherwise clause are executed only if all Case conditions are evaluated as false.

Note: In Native Mobile applications, it works on both Client-side and Server-side events.


Samples

The following code can be defined, for example, inside a GeneXus object Event or Source:

Do Case
    Case &Today.Month()=1
          &Discount=15
          &Bonus=500
    Case &Today.Month()=2
          &Discount=10
          &Bonus=300
    Otherwise
          &Discount=5
          &Bonus=0
Endcase

See Also

Sub command


Last update: November 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant