While Loop in OIC Explained
While Loop in OIC Explained: Complete Guide with Examples
Oracle Integration Cloud (OIC) provides several logic actions that help developers build dynamic integration workflows. One of the most useful is the While action, which allows an integration to repeatedly execute actions or invoke connections as long as a specified condition remains true.
Unlike a For Each loop, which is primarily used to process every item in a repeating collection, a While loop in OIC is condition-driven. The loop continues executing until its condition evaluates to false. Oracle documents the While action as a logic action available for both scheduled and application integrations.
In this guide from Learnomate Technologies, we will understand the While Loop in OIC, how to configure it, practical examples, differences between While and For Each, error handling, common mistakes, and best practices.
What Is a While Loop in OIC?
The While action in Oracle Integration Cloud is used to repeatedly execute a group of actions or invoke connections while a specified condition is satisfied.
The basic concept is:
Start
|
v
Check Condition
|
+---- TRUE ----> Execute Actions
| |
| v
| Update Variable
| |
| v
+------------- Check Condition
|
+---- FALSE ---> Continue Integration
For example, suppose you want to call an API repeatedly until a process reaches the COMPLETED status.
The logic can be:
While status != "COMPLETED"
|
+--- Call Status API
|
+--- Read Status
|
+--- Update Status
Once the status becomes COMPLETED, the condition becomes false and the loop ends.
Oracle’s OIC documentation explains that the condition is defined using the Expression Builder, and the actions inside the While scope execute as long as that condition is met.
Why Use a While Loop in OIC?
A While loop is useful when you don’t know the exact number of iterations in advance.
For example:
- Continue polling an API until a job completes.
- Continue pagination until no more records are available.
- Retry a business operation while a condition remains true.
- Process data until a counter reaches a particular value.
- Continue checking an asynchronous process status.
- Retrieve pages of records until the last page is reached.
For example:
Start
|
v
Check Job Status
|
+-- RUNNING --> Check Again
|
+-- COMPLETED --> Continue
|
+-- FAILED --> Error Handling
This is a typical situation where a While loop is more appropriate than a For Each loop.
While Loop vs For Each Loop
One of the most important concepts for OIC developers is understanding when to use While and when to use For Each.
| Feature | While Loop | For Each Loop |
|---|---|---|
| Main purpose | Repeat while condition is true | Process items in a collection |
| Driven by | Boolean/conditional expression | Repeating element |
| Number of iterations | Determined at runtime | Based on collection size |
| Collection required | No | Yes |
| Common use | Polling, pagination, status checking | Employees, orders, files |
| Condition required | Yes | No |
| Example | status != COMPLETE |
For Each employee |
For Each Example
For Each Employee
|
+--- Process Employee
While Example
While Job Status = RUNNING
|
+--- Check Job Status
The key difference is:
For Each is collection-driven, while While is condition-driven.
Oracle categorizes both For Each and While under integration logic actions, but their purposes are different.
How to Create a While Loop in OIC
Let’s understand the configuration step by step.
Step 1: Create an Integration
Log in to your Oracle Integration environment.
Navigate to the integration designer and create an appropriate orchestration.
For example:
Integration Name:
Check Job Status
You can use an application-driven or scheduled integration depending on your requirement. The While action is available in both scheduled and application integrations.
Step 2: Create a Variable
A While loop normally needs a variable or value that changes during execution.
For example:
Variable Name:
counter
Initial value:
0
You could also create a status variable:
jobStatus = "RUNNING"
Variables used in While conditions can include types such as numbers, strings, and booleans.
Step 3: Add the While Action
From the Actions palette, select:
While
Drag it onto the integration canvas.
Alternatively, click the + icon at the appropriate location and select While. Oracle’s current OIC documentation describes both methods for adding a While action.
Step 4: Configure the Condition
The Configure While panel allows you to define the condition using the Expression Builder.
For example:
counter <= 10
or:
jobStatus != "COMPLETED"
Conceptually:
WHILE counter <= 10
The loop continues while the expression evaluates to true.
When it becomes false, OIC exits the loop and continues with the next action in the integration.
Oracle’s documentation provides an example in which a counter is compared against a maximum value, with processing ending when the condition is no longer satisfied.
Step 5: Add Actions Inside the While Loop
Once the condition is configured, actions can be added inside the While action.
For example:
While counter <= 10
|
+--- Logger
|
+--- Assign
Oracle allows invoke connections and other actions to be placed inside the While action. These actions execute as long as the configured condition remains true.
Step 6: Update the Variable
This is one of the most important steps.
Suppose your condition is:
counter <= 10
You need to change counter inside the loop.
For example:
counter = counter + 1
The execution becomes:
counter = 0
|
v
0 <= 10 → TRUE
|
counter = 1
|
v
1 <= 10 → TRUE
|
counter = 2
|
...
|
counter = 11
|
11 <= 10 → FALSE
|
v
Exit Loop
If the value controlling the condition never changes, the loop can continue indefinitely.
Practical Example 1: Counter-Based While Loop
Let’s start with a simple example.
Requirement
Print numbers from 1 to 5 using a While loop.
Create:
counter = 1
Condition:
counter <= 5
Inside the loop:
Logger → Print counter
Assign → counter = counter + 1
The flow becomes:
counter = 1
|
v
counter <= 5?
|
+--- YES
| |
| +--- Logger
| |
| +--- counter = counter + 1
| |
| v
+------- Check Again
|
+--- NO
|
v
Continue
Output:
1
2
3
4
5
Practical Example 2: Polling an API Until Job Completion
This is one of the most useful real-world applications of a While loop.
Suppose OIC submits a job to an external system.
The external system returns:
{
"jobId": "10001",
"status": "RUNNING"
}
OIC needs to repeatedly check the job status.
The integration can be:
Submit Job
|
v
Get Job Status
|
v
While status != "COMPLETED"
|
+--- Wait
|
+--- Get Job Status
|
+--- Update status
|
v
Continue
The loop continues while:
status != "COMPLETED"
When the API returns:
{
"status": "COMPLETED"
}
the condition becomes false and the loop ends.
Practical Example 3: Pagination Using While Loop
Pagination is another common OIC use case.
Suppose an API returns 100 records per page.
The API provides:
page = 1
hasMore = true
You want OIC to continue retrieving pages until there are no more records.
The logic could be:
While hasMore = true
|
+--- Invoke API
|
+--- Process Response
|
+--- Read next page
|
+--- Update hasMore
Example:
Page 1
|
+--- hasMore = true
|
Page 2
|
+--- hasMore = true
|
Page 3
|
+--- hasMore = false
|
v
Exit Loop
Oracle lists pagination as one of the use cases for the While action in OIC.
Practical Example 4: Processing Until a Status Changes
Consider an integration that submits an employee synchronization job.
Initially:
status = "PROCESSING"
The While condition is:
status = "PROCESSING"
Inside the loop:
Invoke Status API
|
v
Read Status
|
v
Assign status
The flow is:
Submit Job
|
v
status = PROCESSING
|
v
While status = PROCESSING
|
+--- Invoke Status API
|
+--- Update status
|
v
Status COMPLETED
|
v
Exit Loop
This is a common pattern when integrating with asynchronous APIs.
Practical Example 5: While Loop with Wait
When polling an external service, continuously calling the API may create unnecessary traffic.
You can introduce a Wait action inside the loop.
For example:
While status != "COMPLETED"
|
+--- Wait 30 seconds
|
+--- Invoke Status API
|
+--- Update Status
This gives the external system time to process the job before OIC checks again.
The Wait action is useful when the integration needs to delay execution for a specified period. OIC provides Wait as a separate integration action for this purpose.
Understanding the While Condition
The condition is the heart of a While loop.
Examples include:
Numeric Condition
counter < 100
String Condition
status = "RUNNING"
Boolean Condition
hasMore = true
Compound Condition
status = "RUNNING" AND retryCount < 5
You can create these conditions through the Expression Builder.
OIC allows values from the Sources tree to be selected or manually entered, along with operators and functions.
What Happens When the Condition Becomes False?
Consider:
While counter <= 3
Execution:
counter = 1 → TRUE
counter = 2 → TRUE
counter = 3 → TRUE
counter = 4 → FALSE
When the condition evaluates to false, OIC exits the While action and continues with the next action after the loop.
For example:
Start
|
v
While
|
+--- Loop actions
|
v
Assign Result
|
v
End
Variables and Scope in While Loops
Variable scope is important when designing OIC loops.
Oracle notes that variables created inside a scope or looping action, such as a While or For Each action, are not directly accessible outside that scope or loop. If a value needs to be used outside the loop, you can create a global variable above the looping action and assign the local value to it.
For example:
Global Variable
|
v
While
|
+--- Local Variable
|
+--- Processing
|
v
Assign Result to Global Variable
|
v
Next Action
This is especially important when you need the final value calculated inside the loop later in the integration.
While Loop and Error Handling
While loops often contain invoke actions, so error handling should be considered carefully.
For example:
While status = "RUNNING"
|
+--- Scope
|
+--- Invoke API
|
+--- Assign
|
+--- Fault Handler
A Scope can group related actions and provide fault-handling behavior.
A good design should define what happens if:
- API invocation fails.
- The status API is unavailable.
- A response contains invalid data.
- The loop reaches a maximum retry count.
- The external system returns an unexpected status.
Preventing Infinite Loops
One of the biggest risks when using a While loop is an infinite loop.
Consider:
While counter <= 10
|
+--- Logger
If counter is never updated, it remains:
counter = 0
Therefore:
0 <= 10 → TRUE
will continue to be true.
The loop never reaches its exit condition.
Better Design
Always make sure something inside the loop changes the condition.
While counter <= 10
|
+--- Process
|
+--- counter = counter + 1
Use a Maximum Retry Count
For polling and retry scenarios, it is a good practice to use a maximum attempt count.
For example:
retryCount = 0
Condition:
status != "COMPLETED"
AND
retryCount < 10
Inside:
Wait
|
Invoke API
|
Update Status
|
retryCount = retryCount + 1
Now the loop has two possible exit conditions:
Job completed
OR
Maximum attempts reached
This is safer than relying only on the external status.
While Loop with Nested Logic
A While loop can contain other actions such as:
- Assign
- Switch
- Scope
- Invoke
- Logger
- Wait
- For Each
For example:
While hasMore = true
|
+--- Invoke API
|
+--- Switch
| |
| +--- Success
| |
| +--- Error
|
+--- Assign
|
+--- For Each Record
This allows you to build more sophisticated integration workflows.
While Loop and For Each Together
Sometimes an integration needs both types of loops.
For example, an API uses pagination and each page contains multiple records.
You could have:
While hasMore = true
|
+--- Invoke API
|
+--- For Each Record
| |
| +--- Process Record
|
+--- Update Page
|
+--- Update hasMore
Here:
- While handles pagination.
- For Each handles records within each page.
This is a very common integration design pattern.
Monitoring a While Loop in OIC
After activating the integration, you can monitor While action execution from OIC’s runtime monitoring area.
Oracle documentation states that While actions can be tracked through the integration instance’s tracking diagram and activity stream. Failures can be identified in the runtime details.
This is useful when troubleshooting:
Integration Instance
|
v
While Action
|
+--- Iteration 1
+--- Iteration 2
+--- Iteration 3
+--- Failure
Monitoring the iteration information can help determine where the integration failed.
Common Mistakes When Using While Loop in OIC
1. Forgetting to Update the Condition Variable
Example:
While counter < 10
but counter never changes.
Result: Potential infinite loop.
Solution: Update the variable inside the loop.
2. No Maximum Retry Limit
Polling an external system without a maximum number of attempts can cause unnecessary processing.
Solution:
Use:
retryCount < 10
along with your business condition.
3. Polling Too Frequently
Calling an API continuously without a delay can unnecessarily increase API traffic.
Solution: Consider adding a Wait action between status checks where appropriate.
4. Using While When For Each Is More Appropriate
If you already have a collection such as:
employees[]
and need to process each employee, For Each is usually the appropriate action.
Use While when the number of iterations depends on a condition.
5. Not Handling API Failures
A status-check API can fail.
Always consider appropriate fault handling around critical invoke actions.
Best Practices for While Loops in OIC
1. Always Define a Clear Exit Condition
Ask:
What causes this loop to stop?
If the answer isn’t clear, redesign the loop.
2. Update the Condition
Make sure something inside the loop changes the condition.
3. Add a Maximum Iteration or Retry Limit
For polling and retry scenarios, don’t rely only on the external system.
4. Use Wait for Polling
When checking asynchronous jobs, avoid unnecessary rapid API calls.
5. Keep the Loop Lightweight
Put only the actions necessary for each iteration inside the loop.
6. Use Meaningful Variable Names
Prefer:
jobStatus
retryCount
hasMoreRecords
currentPage
instead of:
x
a
temp1
7. Design Error Handling
Think about what happens if an action inside the loop fails.
8. Monitor Runtime Instances
Use OIC monitoring to identify iteration failures and understand runtime behavior.
Real-World Use Cases of While Loop in OIC
1. API Polling
Submit Job
↓
While Job Not Complete
↓
Wait
↓
Check Status
2. Pagination
While hasMore = true
↓
Get Next Page
↓
Process Records
3. Retry Processing
While retryCount < 5
↓
Call API
↓
Check Result
4. Batch Processing
While recordsRemaining > 0
↓
Process Batch
↓
Update Remaining Count
5. Asynchronous Job Monitoring
Start Job
↓
While status = RUNNING
↓
Check Status
↓
Continue
While Loop Example for OIC Interview
Interview Question:
How do you use a While loop in Oracle Integration Cloud?
Answer:
A While action in OIC is used to repeatedly execute a group of actions or invoke connections while a specified condition evaluates to true.
For example, if an external system processes a job asynchronously, OIC can submit the job and then use a While loop to repeatedly check its status.
Submit Job
|
v
While status != COMPLETED
|
+--- Wait
|
+--- Check Status API
|
+--- Update Status
|
v
Continue Integration
The loop ends when the condition becomes false.
Frequently Asked Questions
What is a While Loop in OIC?
A While Loop is an OIC logic action that repeatedly executes actions or invokes connections while a specified condition is true.
Where is the While action available in OIC?
The While action is available in both scheduled and application integrations.
What is the difference between While and For Each in OIC?
While is condition-based, whereas For Each is collection-based and processes the items in a repeating element.
Can a While loop call an API?
Yes. Invoke connections can be placed inside the While action and are executed while the condition remains satisfied.
Can I use a Wait action inside a While loop?
Yes. A Wait action can be used when you need to introduce a delay, which is particularly useful when polling asynchronous processes.
How can I prevent an infinite loop in OIC?
Make sure the condition can eventually become false and consider adding a maximum retry or iteration counter.
Can I use For Each inside a While loop?
Yes. This can be useful for scenarios such as API pagination, where the While loop handles pages and the For Each loop processes records within each page.
Can While loops be monitored in OIC?
Yes. Runtime instances can be monitored through OIC’s tracking and activity-stream information, including While action failures and iteration details.
Final Thoughts
The While Loop in Oracle Integration Cloud is an essential tool for building condition-driven integrations.
It is especially valuable when the number of iterations isn’t known beforehand and depends on a runtime condition.
The basic pattern to remember is:
Initialize Variable
|
v
Check Condition
|
+--- TRUE
| |
| +--- Execute Actions
| |
| +--- Update Variable
| |
| +----> Check Condition
|
+--- FALSE
|
v
Continue Integration
For production integrations, always pay attention to exit conditions, retry limits, API throttling, Wait actions, error handling, variable scope, and runtime monitoring.
Understanding both While and For Each loops will help OIC developers design more flexible and reliable integrations.
Learnomate Technologies focuses on practical Oracle and cloud technology learning, helping professionals build the skills required to design, troubleshoot, and implement real-world enterprise integrations.
If you are learning OIC, make sure you also understand other important actions such as For Each, Switch, Scope, Assign, Wait, Stage File, Invoke, and Fault Handling.





