diff --git a/SystemTools.cxx b/SystemTools.cxx
index e72e02d2cce082f26764d1dc0550e5af6c3811d3..f6d7641dc7f13fb6ddcf965e2541792728e8531b 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -2079,7 +2079,7 @@ kwsys_stl::string SystemTools::FileExistsInParentDirectories(const char* fname,
   SystemTools::ConvertToUnixSlashes(file);
   kwsys_stl::string dir = directory;
   SystemTools::ConvertToUnixSlashes(dir);
-  while ( 1 )
+  while ( !dir.empty() )
     {
     kwsys_stl::string path = dir + "/" + file;
     if ( SystemTools::FileExists(path.c_str()) )