FOR or WHILE loop
Test RealTime - User Guide
return result;
}
// Near color function
int nearColor( int _color )
{
switch( _color )
{
case WHITE:
case LIGHTGRAY:
return WHITE ;
case RED:
case PINK:
return RED;
//implicit default:
}
return _color ;
}
}
Each implicit block represents a branch.
Since the sum of all possible decision paths includes implicit blocks as well as simple
blocks, reports provide the total number of simple and implicit blocks as a figure and
a percentage after the term decisions.
Loops (Logical Blocks)
Three branches are created in a FOR or WHILE loop:
·
The first branch is the simple block contained within the loop, and that is
executed zero times (the entry condition is false from the start).
·
The second branch is the simple block executed exactly once (entry condition
true, then false the next time).
·
The third branch is the simple block executed at least twice (entry condition true
at least twice, and false at the end).
Two branches are created in a DO/WHILE loop, as the output condition is tested
after the block has been executed:
·
The first branch is the simple block executed exactly once (output condition
false the first time).
·
The second branch is the simple block executed at least twice (output condition
false at least once, then true at the end).
Example
public class LogicalBlocks
{
public static int tryFiveTimes()
{
int result, i=0;
while ( ( ( result=resourcesAvailable() )<= 0)
&& ( ++i < 5 ) );
52