2017-11-18 3 views
-3

このプログラムをif-else-ifステートメントからswitchステートメントに変換するのに問題があります。どんな助けもありがとう。このプログラムをif-else-ifステートメントからswitchステートメントに変換するのに問題があります。どんな助けもありがたいです

public void tick() { 
    if (s.word == 0) 
     return; 

    short t = this.sc.word; 
    short d = this.get_opcode(); 
    short i = this.get_indirect_bit(); 

    if (t == 0 || t == 1) 
     this.instruction_fetch(t); 

    if (t == 2) 
     this.instruction_decode(); 

    if (t == 3 && d != 7) 
     this.operand_fetch(i); 

    if (t > 3 && d != 7) 
     this.execute_mri(d, t); 

    if (t == 3 && d == 7) { 
     this.execute_rri((short) (this.ir.word & 0xFFF)); 
    } 
} 
+5

そのhasn働いた?それが立てば、これはちょうど「私のためのコードを書くことができますか?」です。 – Withnail

+0

'&&'ステートメントを大文字と小文字の区別なく簡単に変更することはできません。もしあなたがどこかにいる必要があります –

答えて

1

それは完全に「IF」文を排除することはできませんが、このコードは、あなたが探しているものでなければなりません:switch文をやっています* *試してみました何

if (s.word == 0) 
    return; 
short t = this.sc.word; 
short d = this.get_opcode(); 
short i = this.get_indirect_bit(); 

switch(t) { 
    case 0: 
    case 1: 
     this.instruction_fetch(t); 
     break; 
    case 2: 
     this.instruction_decode(); 
     break; 
    case 3: 
     if(d ==7) { 
      this.execute_rri((short) (this.ir.word & 0xFFF)); 
     } 
     else { 
      this.operand_fetch(i); 
     } 
     break; 
    default: 
     if(d!=7) this.execute_mri(d, t); 
     break; 
} 
関連する問題