while - Pine Script Keyword
Overview
Section titled “Overview”The while statement allows the conditional iteration of a local code block.
Syntax
Section titled “Syntax”variable_declaration = while condition … continue … break … return_expressionRemarks
Section titled “Remarks”- The local code block after the initial while line must be indented with four spaces or a tab. For the while loop to terminate, the boolean expression following while must eventually become false, or a break must be executed.
Example
Section titled “Example”//@version=6indicator("while")// This is a simple example of calculating a factorial using a while loop.int i_n = input.int(10, "Factorial Size", minval=0)int counter = i_nint factorial = 1while counter > 0 factorial := factorial * counter counter := counter - 1plot(factorial)