If inside while

Hi all, have a good day,
My issue in the code that it sometimes prompt the sign " +"
I'm trying to find the bandwidth of a sparse matrix.
I'd be grateful if you can help
here's the code

#check bandwidth 
i <-array(c(1), dim=c(1))
j<-array(c(1), dim=c(1))
k1<-0
k2<-0
while(j<=ceiling(c/2)){
  while(j<=(i-k1)){
    if(A[i]==0 & A[j]==0)
      {
      k1<-k1+1
      } else {ifelse(i==c,j<-j+1,i<-i+1)
      }
  }
}
i <-array(c(1), dim=c(1))
j<-array(c(ceiling(c/2)), dim=c(1))
    while(j>=ceiling(c/2)){
 while(j<(i+k2)){
if(A[i]==0 & A[j]==0)
  {
    k2<-k2+1}
    else {
ifelse(i==c,j<-j+1,i<-i+1)
   }
}
}

The code violates two of my personal admonitions:

  1. Never name a variable after a built-in (c).
  2. If an operation must be done in procedural/functional style and fails, write it in C/C++ or {reticulate} Python.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.