What Are The Conditional Statements In Apex?

For Loop:
Conditional_Statements_In_Apex

Apex supports three variations of the for loop:
The traditional for loop:
for (init_stmt; exit_condition; increment_stmt) 
{
     code_block
}

The list or set iteration for loop:
for (variable : list_or_set) 
{
    code_block
}

where variable must be of the same primitive or sObject type as list_or_set.
The SOQL for loop:
for (variable : [soql_query]) 
{
    code_block
}
or
for (variable_list : [soql_query]) 
{
    code_block
}

Both variable and variable_list must be of the same sObject type as is returned by the soql_query.

If-Else:
The conditional statement in Apex works similarly to Java:
Syntax:
if ([Boolean_condition])
{
Statement 1 
}
else
{
  Statement 2 
}

The else portion is always optional, and always groups with the closest if.
Example:
Integer x, sign;
// Your code 
    if (x <= 0) if (x == 0) sign = 0; else sign = -1;

is equivalent to:
Integer x, sign;
// Your code 
if (x <= 0) {
    if (x == 0) {
           sign = 0;
    } else  {
           sign = -1;
    }
}

Repeated else if statements are also allowed.
For example:
if (place == 1) {
    medal_color = 'gold';
} else if (place == 2) {
    medal_color = 'silver';
} else if (place == 3) {
    medal_color = 'bronze';
} else {
    medal_color = null;
}

While Loops:
              The Apex​​ while loop repeatedly executes a block of code as long as a particular Boolean condition remains true.
Syntax:
while (condition) {
    code_block
}

Unlike do-while, the while loop checks the Boolean condition statement before the first loop is executed. Consequently, it is possible for the code block to never execute.
Integer count = 1;
while (count < 11) {
    System.debug(count);
    count++;
}


Do-While Loops:
        The Apex​​ do-while loop repeatedly executes a block of code as long as a particular Boolean condition remains true.
Syntax:
do {
   code_block
} while (condition);

As in Java, the Apex​​ do-while loop does not check the Boolean condition statement until after the first loop is executed. Consequently, the code block always runs at least once. As an example, the following code outputs the numbers 1 - 10 into the debug log:
Integer count = 1;
do {
    System.debug(count);
    count++;
} while (count < 11);

COMMENTS

Name

Apex Apex Default Methods Apex Methods Apex_Collections Apps Batch Apex Books CRM eBooks Data Import Wizard Data Management DataLoader Dataloader.io Difference Between Error in Salesforce FAQ's FAQ's-Apex FAQ's-Apps FAQ's-CRM FAQ's-Data loader FAQ's-SOQL & SOSL FAQ'S-Triggers FAQ's-User Profile & Security FAQ's-VF Force.com Explorer Force.com Ide Formulas & Functions Integration Interview Questions Only Latest_Updates Limits&Best Practices Online-Training Reports and Dashboards Salesforce Deployment Salesforce Realtime Examples On Development Salesforce Realtime Task On Admin Salesforce Realtime Tasks Salesforce Realtime Tasks- Apex Salesforce Training Salesforce1 Mobile Sites SOQL Spring'14 Release Triggers User Profile & Security VF Tags VisualForce Winter'14 Release Wizard for Accounts/Contacts Workbench Workflows and Approvals
false
ltr
item
Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners: What Are The Conditional Statements In Apex?
What Are The Conditional Statements In Apex?
What Are The Conditional Statements In Apex?,conditional statements in apex,conditional statements in salesforce,apex conditional statements,apex conditional statements in salesforce
http://3.bp.blogspot.com/-89Z4UiAJW5Q/U0jIk9xMJBI/AAAAAAAABr0/3gu0JW88EbA/s1600/Conditional_Statements_In_Apex.jpg
http://3.bp.blogspot.com/-89Z4UiAJW5Q/U0jIk9xMJBI/AAAAAAAABr0/3gu0JW88EbA/s72-c/Conditional_Statements_In_Apex.jpg
Sfdc Gurukul- All in one place for salesforce and force.com step by step tutorial for beginners
http://sfdcgurukul.blogspot.in/2013/07/what-are-conditional-statements-in-apex.html
http://sfdcgurukul.blogspot.in/
http://sfdcgurukul.blogspot.com/
http://sfdcgurukul.blogspot.com/2013/07/what-are-conditional-statements-in-apex.html
true
4199533888133360731
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy