Announcement
Collapse
No announcement yet.
switch (Step)
Collapse
X
-
David:
It's just an alternative to if/then loops... makes the code a little easier to manage and read.
var DayOfWeek;
DayOfWeek = retrieveDay();
switch( DayOfWeek ) {
case 1: doSundayTask(); break;
case 2: doMondayTask(); break;
case 3: doTuesdayTask(); break;
case 4: doWednesdayTask(); break;
default: doSomeOtherTask(); break;
}
Chris
-
thanks Chris, I am getting the hang of it now...
var Step = 0;
function preMain()
{ setStudyTitle("SwitchDemo2");
debugClear();
setPriceStudy(true);
}
function main()
{ if (getCurrentBarIndex()==0)
{
switch(Step)
{
case 0:
setPriceBarColor(Color.yellow);
debugPrintln("case "+Step+": yellow bars");
Step++;
break;
case 1:
setPriceBarColor(Color.lime);
debugPrintln("case "+Step+": lime bars");
Step++;
break;
case 2:
setPriceBarColor(Color.red);
debugPrintln("case "+Step+": red bars");
Step=0;
break;
}
}
}
Comment
Comment