diff --git a/loopy/compiled.py b/loopy/compiled.py
index 02730d8688117d9f58407d243546d04328e365b1..c5928d6e7cd96b5e60d60b0c5dd13e21e33fb67f 100644
--- a/loopy/compiled.py
+++ b/loopy/compiled.py
@@ -502,7 +502,7 @@ def generate_array_arg_setup(gen, kernel, impl_arg_info, options):
                 if kernel_arg.shape is None:
                     pass
 
-                if any(shape_axis is None for shape_axis in kernel_arg.shape):
+                elif any(shape_axis is None for shape_axis in kernel_arg.shape):
                     gen("if len(%s.shape) != %s:"
                             % (arg.name, len(arg.unvec_shape)))
                     with Indentation(gen):