简体   繁体   中英

figuring out what counts as an instruction in java code

I'm trying to figure out what constitutes an instruction in java code. In class lecture that I attended professor mentioned 7 things that can be constituted as instruction but. I am having trouble making out what.

assignment, access of array, return statement, addition multiplication subtraction,..

Here is a example code she gave out:

int sum = 0;
int i = 0;
while ( i < 3 ) {
    sum += A[ i ];
    i++;
}

she says there are total of 18 instructions in this java code but I only count 15. Could you guys clarify why this is.

I believe something is missed in the explanation what count as instruction

Taking this schema there would be twenty.

1) int sum = 0;       // 1 assignment
2) int i = 0;         // 1 assignment
3) while ( i < 3 ) {  // 1 comparison
4)     sum += A[ i ]; // 1 array access, 1 addition, 1 assignment --> sum = sum + A[i]
5)     i++;           // 1 addition, 1 assignment --> i = i + 1;
6) }

The lines 3-5 are executed three times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM