Bubble sort

The following is an example of bubble sorting in Game Maker.

GML Example
TOTAL=30; //-// VAR[0] = 55 VAR[1]=11; VAR[2]=6; VAR[3]=18; VAR[4]=17; VAR[5]=2; VAR[6]=3; VAR[7]=1; VAR[8]=19; VAR[9]=25; VAR[10]=20; VAR[11]=16; VAR[12]=5; VAR[13]=26; VAR[14]=27; VAR[15]=9; VAR[16]=21; VAR[17]=4; VAR[18]=15; VAR[19]=28; VAR[20]=22; VAR[21]=24; VAR[22]=7; VAR[23]=30; VAR[24]=10; VAR[25]=29; VAR[26]=14; VAR[27]=23; VAR[28]=8; VAR[29]=12; VAR[30]=13; //-// sorted=false; start=1; wrong=0; repeat(TOTAL) { if startVAR[start+1] {  //Switching occurs tmp1=VAR[start]; tmp2=VAR[start+1]; VAR[start]=tmp2; VAR[start+1]=tmp1; wrong+=1; } start+=1; } sorted=(wrong==0);
 * Create event
 * Actual Sort Action

do { ACTUAL SORT ACTION } until(sorted==true)
 * Now, for actually doing the action in one step, we can use the do-until command: