For faster navigation, this Iframe is preloading the Wikiwand page for For-løkke.

For-løkke

En for-løkke er et begreb indenfor datalogi, og i særdeleshed programmering, som betegner en bestemt type af løkke. For-løkken indgår i de fleste programmeringssprog. En for-løkke kan eksempelvis bruges i det tilfælde, hvor man ved præcist, hvor mange gange nogle bestemte operationer skal gentages.

Dette program viser, hvordan man i Java kan beregne og udskrive de ti første tal i anden potens:

 public class ForTest
 {
    public static void main(args[] a)
    {
       for(int i=0; i<=9; i++)
       {
          System.out.print(i*i + " ");
       }
    }
 }

Princippet er, at man starter med en tællevariabel i, sat til 0. Sidste led i "for-parentesen" angiver, at man skal lægge én til tællevariablen for hver gang operationerne i løkken er udført. Det midterste led fortæller, at denne operation skal gentages så længe i er mindre end eller lig med 9. Til dette meget simple program vil outputtet være:

0 1 4 9 16 25 36 49 64 81
ProgrammeringSpire
Denne artikel om datalogi eller et datalogi-relateret emne er en spire som bør udbygges. Du er velkommen til at hjælpe Wikipedia ved at udvide den.
{{bottomLinkPreText}} {{bottomLinkText}}
For-løkke
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?