| 
									
										
										
										
											2023-02-06 10:40:00 +01:00
										 |  |  | # {while}
 | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | `{while}` loops in Smarty have much the same flexibility as PHP | 
					
						
							| 
									
										
										
										
											2023-02-03 22:31:59 +01:00
										 |  |  | [while](https://www.php.net/while) statements, with a few added features for | 
					
						
							| 
									
										
										
										
											2021-12-03 11:59:22 +01:00
										 |  |  | the template engine. Every `{while}` must be paired with a matching | 
					
						
							| 
									
										
										
										
											2024-03-25 13:54:02 +01:00
										 |  |  | `{/while}`. All [operators](../language-basic-syntax/language-syntax-operators.md) are recognized, such as *==*, | 
					
						
							|  |  |  | *\|\|*, *or*, *&&*, *and*, etc and you can use modifiers as functions, such as *is_array()*. | 
					
						
							| 
									
										
										
										
											2023-02-06 10:40:00 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Examples
 | 
					
						
							|  |  |  | ```smarty | 
					
						
							|  |  |  | {while $foo > 0} | 
					
						
							|  |  |  |   {$foo--} | 
					
						
							|  |  |  | {/while} | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The above example will count down the value of $foo until 1 is reached. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | See also [`{foreach}`](./language-function-foreach.md), | 
					
						
							|  |  |  | [`{for}`](./language-function-for.md) and | 
					
						
							|  |  |  | [`{section}`](./language-function-section.md). |