Updated (still not working)

#include
using namespace std;

int main(){
int M;
int N;

cin>>M;
cin>>N;

int arr[M][N];

for(int i=0;i<M;i++){
    for(int j=0;j<N;j++){
        cin>>arr[M][N];
    }
}

int row_start=0;
int col_start=0;
int row_end=M-1;
int col_end=N-1;

while(row_start<=row_end && col_start<=col_end){

// for printing col start

if(row_start<=row_end && col_start<=col_end){
for(int row=row_start;row<=row_end;row++){
cout<<arr[row][col_start]<<" β€œ<<”,";
}}
col_start++;
if(row_start<=row_end && col_start<=col_end){
// for printing row end
for(int col=col_start;col<=col_end;col++){
cout<<arr[row_end][col]<<" β€œ<<”,";
}}
row_end–;
if(row_start<=row_end && col_start<=col_end){
// for printing col end
for(int row=row_end;row>=row_start;row–){
cout<<arr[row][col_end]<<" β€œ<<”,";
}
}
col_end–;

if(row_start<=row_end && col_start<=col_end){
// for printing row start
for(int col=col_end;col>=col_start;col–){
cout<<arr[row_start][col]<<" β€œ<<”,";
}
}

row_start++;

}
return 0;
}

code worked, but I want to ask are these β€œif” conditions are necessary before every for loop?

For last two loops it’s necessary