Loops can be formed with the usual for and while constructs. However, the loops must have a single entry and a single exit to be vectorized. Following are the examples of correct and incorrect usages of loop constructs.
Example 1: Correct Usage |
|---|
|
while(i<n) { // If branch is inside body of loop
a[i]=b[i]*c[i]; if(a[i]<0.0) { a[i]=0.0; } i++; } |
Example 2: Incorrect Usage |
|---|
|
while(i<n) { if (condition) break; // 2nd exit. ++i; } |