diff --git a/src/BODY/fix_wall_body_polygon.cpp b/src/BODY/fix_wall_body_polygon.cpp
index 5ec5a7cca8eb30309294a14b13f8e2d10e56bd26..0e7aaea1e1a2a6c9ac0060c092eb703eaf90f2b6 100644
--- a/src/BODY/fix_wall_body_polygon.cpp
+++ b/src/BODY/fix_wall_body_polygon.cpp
@@ -641,18 +641,15 @@ int FixWallBodyPolygon::compute_distance_to_wall(double* x0, double rradi,
     mode = VERTEX;
     contact = 1;
   } else {
+    mode = NONE;
     if (side == XLO) {
       if (x0[0] < wall_pos) mode = VERTEX;
-      else mode = NONE;
     } else if (side == XHI) {
       if (x0[0] > wall_pos) mode = VERTEX;
-      else mode = NONE;
     } else if (side == YLO) {
       if (x0[1] < wall_pos) mode = VERTEX;
-      else mode = NONE;
     } else if (side == YHI) {
       if (x0[1] > wall_pos) mode = VERTEX;
-      else mode = NONE;
     }
   }