diff --git a/miscmaths.cc b/miscmaths.cc
index a02259bcfacc12bf881abb247bb4b7c099554e1e..f23ae8cddf7d6a6621fa36377489a1750e25b657 100644
--- a/miscmaths.cc
+++ b/miscmaths.cc
@@ -1555,7 +1555,7 @@ void element_mod_n(Matrix& Mat,double n)
 
   double tmp;
   for( int j=1;j<=Mat.Ncols();j++){
-    for( int i=1;j<=Mat.Nrows();i++){
+    for( int i=1;i<=Mat.Nrows();i++){
 
       if( !( (Mat(i,j)>0) && (Mat(i,j)<n) ) ){ 
 	tmp = ( Mat(i,j) - MISCMATHS::round(Mat(i,j)/n)*n );