Loops – Exercises
Quiz Summary
0 of 16 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
Results
Results
0 of 16 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Categories
- Not categorized 0%
-
Unfortunately, your results in the simulator were not up to the desired standards. 😔
However, take advantage of your unlimited access and continue to practice.
Remember, persistence and dedication will lead to mastery. 😎 -
Congratulations! 🎉
You have successfully passed the simulator and are now one step closer to achieving your certification.
We hope you will consider joining us again in your future certification journey.Wishing you the best of luck with the upcoming exam. Keep up the great work! 💪
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- Current
- Review
- Answered
- Correct
- Incorrect
-
Question 1 of 16
1. Question
Jack is writing a Salesforce Apex program to log the message “Welcome to Apex!” exactly 5 times using a
do-whileloop. He’s set up a variabletimesShownfor counting.Fill in the blanks to complete the loop:
-
String message = “Welcome to Apex!”;
Integer timesShown = 1;
do {
System.debug( );
;
} while ( <= 5);
CorrectIncorrect -
-
Question 2 of 16
2. Question
While learning about loops in Salesforce Apex, Jenny wants to create a loop that logs the message “Apex is fun!” five times. She has initialized a variable named
loopCounter.Fill in the blanks to help Jenny complete her loop:
-
String message = “Apex is fun!”;
Integer loopCounter = 1;
do {
System.debug( );
;
} while ( <= 5);
CorrectIncorrect -
-
Question 3 of 16
3. Question
To understand the mechanics of
do-whileloops, a developer wants to print all numbers between 1 and 5 inclusive. They’ve initialized anumvariable for this purpose.Complete the loop to achieve this:
-
Integer num = 1;
do {
System.debug( );
;
} while ( <= 5);
CorrectIncorrect -
-
Question 4 of 16
4. Question
A Salesforce developer needs to display the phrase “Learning Apex!” exactly 4 times. They have initialized a variable
iterationsto 1.Complete the
do-whileloop to achieve this:-
String phrase = “Learning Apex!”;
Integer iterations = 1;
do {
System.debug( );
;
} while (iterations 4);
CorrectIncorrect -
-
Question 5 of 16
5. Question
Jake is aiming to practice Salesforce Apex by printing the phrase “Apex Rocks!” exactly three times using a
whileloop. He’s already set up a counter callediterations.Complete the loop for him:
-
String phrase = “Apex Rocks!”;
Integer iterations = 1;
while ( <= 3) {
System.debug( );
;
}
CorrectIncorrect -
-
Question 6 of 16
6. Question
Maria wants to log all even numbers between 2 and 8 inclusive using a
whileloop in her Salesforce Apex program. She initializes the variableevenNum.Help her fill in the blanks to achieve this:
-
Integer evenNum = 2;
while ( <= 8) {
System.debug( );
2;
}
CorrectIncorrect -
-
Question 7 of 16
7. Question
Tom is practicing Salesforce Apex and aims to print the message “Learning Apex!” four times using a
whileloop. He’s set a counter variable namedrepeats.Fill in the blanks to help him:
-
String text = “Learning Apex!”;
Integer repeats = 1;while ( < 5) {
System.debug( );
++;
}
CorrectIncorrect -
-
Question 8 of 16
8. Question
Lisa is working on a Salesforce Apex program and wishes to log all odd numbers from 1 to 7 using a
whileloop. She starts by initializing the variableoddNum.Complete the loop to achieve this:
-
Integer oddNum = 1;
while ( <= 7) {
System.debug( );
+= 2;
}
CorrectIncorrect -
-
Question 9 of 16
9. Question
Daniel wishes to log the numbers 5 through 15 in his Salesforce Apex program using a traditional
forloop.Can you assist him by completing the blanks in his loop?
-
for (Integer n = , m = 0; n <= ; ++) { System.debug(n); }
CorrectIncorrect -
-
Question 10 of 16
10. Question
Alex is trying to create a Salesforce Apex program that logs every third number starting from 3 and ending at 12 using a traditional
forloop. He has begun the loop structure but needs help with the conditions.Complete the blanks for him:
-
for (Integer k = , x = 0; k <= ; k+= ) {
System.debug(k);
}
CorrectIncorrect -
-
Question 11 of 16
11. Question
Sophia is developing a Salesforce Apex program to calculate the total of the first 5 even numbers. She has initialized a sum variable to 0 and wishes to iterate through these numbers using a traditional
forloop.Assist her by filling in the blanks:
-
Integer sum = 0;
for (Integer i = , j = 0; i <= ; i+= ) {
sum += i;
}
System.debug(sum);
CorrectIncorrect -
-
Question 12 of 16
12. Question
Ella is trying to write a program in Salesforce Apex to sum up the first five positive numbers using a traditional
forloop. She has a variablesumto keep track of the total and wants to use a loop control variablenumCount.Complete the blanks to help her:
-
Integer sum = 0;
for (Integer numCount = 1, dummyVar = 0; <= 5; ) {
sum += ;
}
System.debug(sum);
CorrectIncorrect -
-
Question 13 of 16
13. Question
Jane is working on a Salesforce project where she is provided with a list of product prices. She needs to iterate over each price and log the value for further review. Given the following list:
List<Decimal> productPrices = new List<Decimal>{19.99, 29.99, 49.99, 99.99};
Fill in the blanks to correctly iterate over the list and debug each product price:
-
for ( price : ) {
System.debug( );
}
CorrectIncorrect -
-
Question 14 of 16
14. Question
You are provided with a set of product IDs that need to be checked for processing. Given the set:
Set<Integer> productIds = new Set<Integer>{101, 102, 103, 104};
Complete the following to loop through each product ID and log its value:
-
for ( id : ) {
System.debug( );
}
CorrectIncorrect -
-
Question 15 of 16
15. Question
You are given a list of Account Names and are tasked with iterating over each of them to log their value.
Here’s the list:
List<String> accountNames = new List<String>{‘Acme Corp’, ‘Global Tech’, ‘Innovate Solutions’, ‘Tech Titans’};
Fill in the blanks to correctly iterate over the list and debug each Account Name:
-
for ( account : ) {
System.debug( );
}
CorrectIncorrect -
-
Question 16 of 16
16. Question
Lily is organizing a lucky draw event and has a set of unique ticket numbers. She wants to validate each ticket number by printing it.
Fill in the blanks to achieve this:
-
Set ticketNumbers = new Set{1023, 1054, 1078};
for ( ticket : ) {
System.debug(ticket);
}
CorrectIncorrect -