ArnoldC is an esoteric language which uses movie lines(dialogues) of Arnold Schwarzenegger. It can be used to do many basic programs. I was trying to write a nested loop in it but was not able to create it. Is it possible to write nested loop in ArnoldC?
Sure you can. You just have to declare all your loop variables outside (you can't declare them in), and initialize them every round (after the condition variable succeeded). Then you can nest loops before the outer CHILL
call.
I'll provide an example using a counter-loop, which builds on a flag variable and a counter variable, and print both counters as a four digits number. Comments are after #
, note they must not be in code (and you can Try it online!):
IT'S SHOWTIME
# declare outer and inner loop flags
HEY CHRISTMAS TREE loop
YOU SET US UP @NO PROBLEMO
HEY CHRISTMAS TREE innerloop
YOU SET US UP @NO PROBLEMO
# declare outer and inner loop counters
HEY CHRISTMAS TREE counter
YOU SET US UP @I LIED
HEY CHRISTMAS TREE innercounter
YOU SET US UP @I LIED
# declare variable for calculations
HEY CHRISTMAS TREE calc
YOU SET US UP @I LIED
# outer loop, using `loop` and `counter`
STICK AROUND loop
# decrease outer counter
GET TO THE CHOPPER counter
HERE IS MY INVITATION counter
GET UP 1
ENOUGH TALK
# prepare inner loop variables - set flag to TRUE and counter to 0
GET TO THE CHOPPER innerloop
HERE IS MY INVITATION @NO PROBLEMO
ENOUGH TALK
GET TO THE CHOPPER innercounter
HERE IS MY INVITATION @I LIED
ENOUGH TALK
STICK AROUND innerloop
# decrease inner counter
GET TO THE CHOPPER innercounter
HERE IS MY INVITATION innercounter
GET UP 1
ENOUGH TALK
# calculate outer counter * 100 + inner counter
GET TO THE CHOPPER calc
HERE IS MY INVITATION counter
YOU'RE FIRED 100
GET UP innercounter
ENOUGH TALK
# print it
TALK TO THE HAND calc
# has inner counter reached 10? if so, set loop variable FALSE
GET TO THE CHOPPER innerloop
HERE IS MY INVITATION 10
LET OFF SOME STEAM BENNET innercounter
ENOUGH TALK
CHILL
# has outer counter reached 10? if so, set loop variable FALSE
GET TO THE CHOPPER loop
HERE IS MY INVITATION 10
LET OFF SOME STEAM BENNET counter
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED