This course is currently a work in progress. Please join the waitlist to receive regular updates.
Conditional statements in apex
Conditional statements in Apex allow developers to control the flow of code based on specific conditions. These are runtime decision-making statements that determine what actions should be taken in a given situation.
The following is an example of an if-else conditional check in apex.
Loading...
In the above example:
- The integer variable
age
is initialized with a value of 12. - The
if
statement is used to check if the age is greater than or equal to 18 and prints a message "You are eligible to vote." in the debug logs. - The
else
is executed if the condition in the if statement does not evaluate to true and prints a message "You are not eligible to vote." in the debug logs.
Note
The if statement requires a condition that evaluates to true in order to execute the block of code within it.
Try It Yourself
Loading...
Hide this example
Try It Yourself
Loading...