Rekursive Programmierung unbekannter Tiefe kommt, wenn man so programmieren will, verdammt oft vor und es gibt zahlreiche elegante Algorithmen auf dieser Basis. Kommt bei Verpackungs/Beladungs-Aufgaben sehr oft vor!
Zum Thema Whileloop: Das nachstehende Beispiel ist zwar nur ein doofer Binärzähler, was bekanntlich viel einfacher programmierbar ist - was aber, wenn mache Stellen nicht nur 2 sondern z.B. 5 Zustände haben können.
Und wie kann man da z.B. die Anzahl der ineinander verschachtelten Schleifen per Variable steuerbar zu machen? ("Mit Execute" gilt nicht, da nicht compilierbar)
Code
Cls : Font 2
declare p%[40]
Whileloop 1,1:p%[40]=&Loop
Whileloop 1,1:p%[39]=&Loop
Whileloop 1,1:p%[38]=&Loop
Whileloop 1,1:p%[37]=&Loop
Whileloop 1,1:p%[36]=&Loop
Whileloop 1,1:p%[35]=&Loop
Whileloop 1,1:p%[34]=&Loop
Whileloop 1,1:p%[33]=&Loop
Whileloop 1,1:p%[32]=&Loop
Whileloop 1,1:p%[31]=&Loop
Whileloop 1,1:p%[30]=&Loop
Whileloop 1,1:p%[29]=&Loop
Whileloop 1,1:p%[28]=&Loop
Whileloop 1,1:p%[27]=&Loop
Whileloop 1,1:p%[26]=&Loop
Whileloop 1,1:p%[25]=&Loop
Whileloop 1,1:p%[24]=&Loop
Whileloop 1,1:p%[23]=&Loop
Whileloop 1,1:p%[22]=&Loop
Whileloop 1,1:p%[21]=&Loop
Whileloop 1,1:p%[20]=&Loop
Whileloop 1,1:p%[19]=&Loop
Whileloop 1,1:p%[18]=&Loop
Whileloop 1,1:p%[17]=&Loop
Whileloop 1,1:p%[16]=&Loop
Whileloop 1,1:p%[15]=&Loop
Whileloop 1,1:p%[14]=&Loop
Whileloop 1,1:p%[13]=&Loop
Whileloop 1,1:p%[12]=&Loop
Whileloop 1,1:p%[11]=&Loop
Whileloop 1,1:p%[10]=&Loop
Whileloop 0,1:p%[9]=&Loop
Whileloop 0,1:p%[8]=&Loop
Whileloop 0,1:p%[7]=&Loop
Whileloop 0,1:p%[6]=&Loop
Whileloop 0,1:p%[5]=&Loop
Whileloop 0,1:p%[4]=&Loop
Whileloop 0,1:p%[3]=&Loop
Whileloop 0,1:p%[2]=&Loop
Whileloop 0,1:p%[1]=&Loop
Whileloop 0,1:p%[0]=&Loop
Whileloop 40,0,-1:print p%[&Loop]; :EndWhile :print
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
EndWhile :EndWhile :EndWhile :EndWhile :EndWhile
WaitInput
Alles anzeigen