dimanche 24 janvier 2016

scala for if loop beginner example

I am new to scala and I'm not sure what is the best way to convert a for/if loop I have written in c++ into scala. I'm working on translating my entire document so if someone could give me a first step that would be helpful!

suppose array1, array2, array3 and array4 are all initialised and are of size n-1

The code is

 n=10
 k=4

for(i=0,i<n,i++) {
  if (array1(i) > k){
    array2(i)=0
  }
  else if (array1(i)>-k) { 
    if (array3(i)>0) {
      array2(i)=1
      array4(i)=2
    }
    else {
      array2(i)=2
      array4(i)=0
    }
  else {
    array2(i)=3
    array4(i)=4
  }
}

Aucun commentaire:

Enregistrer un commentaire