控制流图(Control Flow Graph, CFG)

The if Statement

if (x < y)
{
   y = 0;
   x = x + 1;
}
else
{
   x = y;
}

 

控制流图(Control Flow Graph, CFG)

 

if (x < y)
{
   y = 0;
   x = x + 1;
}

 

控制流图(Control Flow Graph, CFG)

The if-return Statement 

if (x < y)
{
   return;
}
print (x);
return;

控制流图(Control Flow Graph, CFG)

注意:2到3 没有边

while and for Loops

x = 0;
while (x < y)
{
   y = f (x, y);
   x = x + 1;
}

 控制流图(Control Flow Graph, CFG)

for (x = 0; x < y; x++)
{
   y = f (x, y);
}

 控制流图(Control Flow Graph, CFG)

do Loop, break and continue

x = 0;
do
{
   y = f (x, y);
   x = x + 1;
} while (x < y);
println (y)

 控制流图(Control Flow Graph, CFG)

x = 0;
while (x < y)
{
   y = f (x, y);
   if (y == 0)
   {
      break;
   } else if (y < 0)
   {
      y = y*2;
      continue;
   }
   x = x + 1;
}
print (y);

 控制流图(Control Flow Graph, CFG)

The Case (switch) Structure

read ( c) ;
switch ( c )
{
   case ‘N’:
      y = 25;
      break;
   case ‘Y’:
      y = 50;
      break;
   default:
      y = 0;
      break;
}
print (y);

控制流图(Control Flow Graph, CFG)

read ( c) ;
switch ( c )
{
   case ‘N’:
      y = 25;
      break;
   case ‘Y’:
      y = 50;
     
   default:
      y = 0;
      break;
}
print (y);

控制流图(Control Flow Graph, CFG)

The Exception (try-catch) Structure

try
{
   s = br.readLine();
   if (s.length() > 96)
      throw new Exception
          (“too long”);
} catch IOException e) {
   e.printStackTrace();
} catch Exception e) {
   e.printStackTrace();
}
return (s);

控制流图(Control Flow Graph, CFG)