diff --git a/src/constant.py b/src/constant.py
index 400e439db2346ad525fbb4722577ca3ce214dd14..8f32dbedb1d9a52626fa749d62cbeec6643723eb 100644
--- a/src/constant.py
+++ b/src/constant.py
@@ -2,6 +2,8 @@
 #    CONSTANT VARIABLES
 #==========================
 
+WHILE_UPPER_BOUND = 1000000
+
 ERROR_WORDS = ['null', "params", "log", "workflow", "it", "config"]
 
 ERROR_WORDS_ORIGINS = ['channel', 'Channel', 'null', "params", "logs", "workflow", "log",
diff --git a/src/outils.py b/src/outils.py
index fdc55357f1c6960c3a406418af124b4e5e9b042d..c941f7183023ec656ee3070c8eb508099624b5ac 100644
--- a/src/outils.py
+++ b/src/outils.py
@@ -1,6 +1,9 @@
 import re
 import subprocess
 import os
+from .constant import WHILE_UPPER_BOUND
+from .bioflowinsighterror import BioFlowInsightError
+
 
 #=============================================================
 # THESE A JUST UTILITY FUNCTIONS TO BE ABLE TO MANIPULATE CODE
@@ -932,7 +935,8 @@ def extract_conditions(code, only_get_inside = True):
     triple_single, triple_double = False, False
 
 
-    while(start<len(code)):         
+    timeout = 0
+    while(start<len(code) and timeout < WHILE_UPPER_BOUND):    
         checked_triple = False
         if(start+3<=len(code)):
             if(code[start:start+3]=="'''" and not quote_single and not quote_double and not triple_single and not triple_double):
@@ -1056,6 +1060,9 @@ def extract_conditions(code, only_get_inside = True):
                     start = end-1
     
             start+=1
+        timeout+=1
+    if(timeout>=WHILE_UPPER_BOUND):
+        raise BioFlowInsightError("The WHILE_UPPER_BOUND was exceeded. BioFlow-Insight was unable to extarct the conditions. Make sure the workflow uses correct Nextflow syntaxe (https://www.nextflow.io/docs/latest/index.html).", type="Unable to extract conditions")
     for c in conditions_dico:
         start, end = conditions_dico[c]
     return conditions_dico