SystemC Jump Statements
一、break ---> 結束循環體
Execution of break statement leads to end of the loop.
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
//break-example
for(int i=0;i<8;i++) {
cout <<" Value of i="<<i<<endl;
if(i == 4) {
cout <<" Calling break"<<endl;
break;
}
}
// Terminate simulation
return 0;
}
SIMULATOR OUTPUT:
j=0 i=4
j=1 i=3
j=2 i=2
j=3 i=1
2、continue ---> 跳過本次循環的剩餘部分,跳到下一次循環
Execution of continue statement leads to skip the execution of statements followed by continue and jump to next loop or iteration value.
#include "systemc.h"
int sc_main (int argc, char* argv[]) {
//continue-example
for(int i=0;i<5;i++) {
cout <<"Before continue, value of i="<<i<<endl;
if((i > 1) && (i < 4)) {
cout <<" Calling continue"<<endl;
continue;
}
cout <<"After continue, value of i="<<i<<endl;
}
// Terminate simulation
return 0;
}
SIMULATOR OUTPUT:
Before continue, value of i=0
After continue, value of i=0
Before continue, value of i=1
After continue, value of i=1
Before continue, value of i=2
Calling continue
Before continue, value of i=3
Calling continue
Before continue, value of i=4
After continue, value of i=4
3、goto ---> 跳到前面放置的label處開始執行
Execution of goto leads to jump to another point in the program.
#include "systemc.h"
#include <iostream>
using namespace std;
int sc_main (int argc, char* argv[]) {
//declaration and initialization
int a = 15;
int b = 10;
my_lable:
cout <<" @ my_label "<<endl;
if( a > b ) {
cout <<" a is greater than b a = "<<a<<" b = "<<b<<endl;
a--;
goto my_lable;
}
else
cout <<" b is greater than a "<<endl;
// Terminate simulation
return 0;
}
SIMULATOR OUTPUT:
@ my_label
a is greater than b a = 15 b = 10
@ my_label
a is greater than b a = 14 b = 10
@ my_label
a is greater than b a = 13 b = 10
@ my_label
a is greater than b a = 12 b = 10
@ my_label
a is greater than b a = 11 b = 10
@ my_label
b is greater than a