diff --git a/src/ModFile.cc b/src/ModFile.cc
index 23f86c7abdcb54531de0ebefa2e8afb6bd70a926..ae13c4ba143764ebd7e5fc0bf4eddd744d35b0bc 100644
--- a/src/ModFile.cc
+++ b/src/ModFile.cc
@@ -823,7 +823,7 @@ ModFile::writeMOutput(const string &basename, bool clear_all, bool clear_global,
     mOutputFile << "warning off" << endl; // This will be executed *after* function warning_config()
 
   if (clear_all)
-    mOutputFile << "if isoctave || matlab_ver_less_than('8.6')" << endl
+    mOutputFile << "if ~isoctave && matlab_ver_less_than('8.6')" << endl
                 << "    clear all" << endl
                 << "else" << endl
                 << "    clearvars -global" << endl