There is NO While concept in Thinkscript! If you have experience with ThinkScript, you will understand there is no need for a "while"!
Each Bar will normally be processed once. The last bar (the bar that has not yet closed) will be processed for each change in the inferred symbol for the Chart (assuming you are using in chart).
Perhaps you should begin with some sample code and then figure out what you want to do.
Here is an intra-day pivot point example courtesy of Mobius. So if you are using intra-day, this may give you some ideas.
# - - BEGIN SCRIPT
# - - Study Name: AAAAA_PivotPoints
input Aggregate = {W, default D, M};
input ShowValuesAtTop = no;
input ShowBubbles = yes;
input ShowOnDaily = yes;
input BubbleOffset = -3;
def today = if getDay() == getLastDay() then 1 else double.NaN;
def Agg = if Aggregate == Aggregate.D then AggregationPeriod.DAY else
if Aggregate == Aggregate.W then AggregationPeriod.WEEK else
if Aggregate == Aggregate.M then AggregationPeriod.MONTH else AggregationPeriod.MIN;
def highestBarNumber = HighestAll(if !IsNaN(close) then BarNumber() else Double.NaN);
def isDaily = if !ShowOnDaily and GetAggregationPeriod() == AggregationPeriod.DAY then yes else no;
def thisOpen = open(period = Agg)[1];
def thisHigh = high(period = Agg)[1];
def thisLow = low(period = Agg)[1];
def thisClose = close(period = Agg)[1];
def thisPP = if isDaily or isNaN(Today) then Double.NaN else (thisHigh + thisLow + thisClose) / 3;
def thisR1 = if isDaily then Double.NaN else (2 * thisPP) - thisLow;
def thisR2 = if isDaily then Double.NaN else thisPP + (thisHigh - thisLow);
def thisR3 = if isDaily then Double.NaN else thisHigh + 2 * (thisPP - thisLow);
def thisR1Mid = if isDaily then Double.NaN else (thisR1 + thisPP) / 2;
def thisR2Mid = if isDaily then Double.NaN else (thisR1 + thisR2) / 2;
def thisS1 = if isDaily then Double.NaN else (2 * thisPP) - thisHigh;
def thisS2 = if isDaily then Double.NaN else thisPP - (thisHigh - thisLow);
def thisS3 = if isDaily then Double.NaN else thisLow - 2 * (thisHigh - thisPP);
def thisS1Mid = if isDaily then Double.NaN else (thisS1 + thisPP) / 2;
def thisS2Mid = if isDaily then Double.NaN else (thisS1 + thisS2) / 2;
plot R3 = thisR3;
plot R2 = thisR2;
plot R1 = thisR1;
plot PP = thisPP;
plot S1 = thisS1;
plot S2 = thisS2;
plot S3 = thisS3;
AddLabel(!isDaily and ShowValuesAtTop, "R3: " + R3, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "R2: " + R2, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "R1: " + R1, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "PP: " + PP, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "S1: " + S1, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "S2: " + S2, Color.WHITE);
AddLabel(!isDaily and ShowValuesAtTop, "S3: " + S3, Color.WHITE);
R3.DefineColor("R3", Color.WHITE);
R3.SetStyle(Curve.SHORT_DASH);
R3.SetLineWeight(1);
R3.HideBubble();
R2.DefineColor("R2", Color.WHITE);
R2.SetStyle(Curve.SHORT_DASH);
R2.SetLineWeight(1);
R2.HideBubble();
R1.DefineColor("R1", Color.WHITE);
R1.SetStyle(Curve.SHORT_DASH);
R1.SetLineWeight(1);
R1.HideBubble();
PP.DefineColor("PP", Color.WHITE);
PP.SetStyle(Curve.SHORT_DASH);
PP.SetLineWeight(1);
PP.HideBubble();
S1.DefineColor("S1", Color.WHITE);
S1.SetStyle(Curve.SHORT_DASH);
S1.SetLineWeight(1);
S1.HideBubble();
S2.DefineColor("S2", Color.WHITE);
S2.SetStyle(Curve.SHORT_DASH);
S2.SetLineWeight(1);
S2.HideBubble();
S3.DefineColor("S3", Color.WHITE);
S3.SetStyle(Curve.SHORT_DASH);
S3.SetLineWeight(1);
S3.HideBubble();
def BubbleBar = if ShowBubbles and (BarNumber() == highestBarNumber - BubbleOffset) then yes else no;
AddChartBubble(BubbleBar, R3, " R3", R3.TakeValueColor(), yes);
AddChartBubble(BubbleBar, R2, " R2", R2.TakeValueColor(), yes);
AddChartBubble(BubbleBar, R1, " R1", R1.TakeValueColor(), yes);
AddChartBubble(BubbleBar, PP, " PP", PP.TakeValueColor(), yes);
AddChartBubble(BubbleBar, S1, " S1", S1.TakeValueColor(), yes);
AddChartBubble(BubbleBar, S2, " S2", S2.TakeValueColor(), yes);
AddChartBubble(BubbleBar, S3, " S3", S3.TakeValueColor(), yes);
# - - END SCRIPT