Examples for finding maximum
Visual Studio 2010 (Similar to VB5, VB6 and Subsequent Visual Basic.NET languages)
In this example it is presumed that the array/list has already been populated.
A list box is used to output the maximum value. It is possible to use a different object for output.
maximum = testscore[0]For counter = 1 To 9If testscore[counter] > maximum Thenmaximum = testscore[counter]End IfNextListBox1.Items.Add("The maximum value was " & maximum)LiveCode
Remember - Live code will index from 1 rather than 0!
In this example it is presumed that the array/list has already been populated.
put testscore[1] into maximumrepeat with loop = 2 to 10if testscore[loop] > maximum thenput testscore [loop] into maximumEnd ifend repeatput “The maximum value was" & &maximum & & into field "output"Python – Version 3.x
In this example it is presumed that the array/list has already been populated.
maximum = testscore[0]for counter in range (1, 10):if testscore[counter] > maximum:maximum = testscore[counter]print ("The maximum value was ", maximum)Java
In this example it is presumed that the array has already been populated.
maximum=testscore[0];for(int counter=1;counter˂10;i++){if(testscore[counter]>maximum){maximum=testscore[counter];}}System.out.println("The maximum value was " + maximum);True BASIC
Remember – True BASIC will index from 1 rather than 0!
In this example it is presumed that the array has already been populated.
LET maximum = testscore(1)FOR counter = 2 to 10IF testscore(counter) > maximum THENmaximum = testscore (counter)END IFNEXT counterPRINT "The maximum value was "; maximumXojo (Formerly REALbasic)
In this example it is presumed that the array has already been populated.
A static text box called ‘maxtext’ has been used to output the maximum value.
maximum = score(0)For counter = 1 to 9If score(counter)>maximum Thenmaximum = score(counter)End IfNextmaxtext.text = “The maximum value was ” + maximumPascal
In this example it is presumed that the array has already been populated.
beginmaximum:=score[0];For counter := 1 to 9 dobeginif score[counter] > maximum thenmaximum:=score[counter];end;writeln(output, 'The maximum value was ', maximum);end.Comal
In this example it is presumed that the array has already been populated.
maximum% := score% (0)FOR counter%:= 1 TO 9 DOIF score% (counter%) > maximum% THENmaximum% := score% (counter%)ENDIFNEXTPRINT “The maximum value was ”, maximum%