0

I am a student from IADT and I do not understand for loops and think that I failed my programming test

Comments
  • 7
    Sorry to hear that, you'll get the hang of it! For loops are different from while loops because while loops keep going until a condition is met (for example, while(myAppIsRunning){}) as opposed to a for loop, which usually runs a specific amount of times. So this loop

    for(int i = 0; i < 10; i++){}

    Will run ten times. The "int i" makes a variable to keep track of the amount of times the loop has looped. This can be used and changed inside the loop. The next thing is the logic; when the loop shpuld stop. In this example, when i is 10, the loop will exit. Lastly, you iterate (add one to the counter) inside the for loop declaration instead of inside the loop itself. So i++ adds one to i every time thr loop goes through. This is the general format of a loop, what language are you using? c?
  • 2
    @AlgoRythm you are a nice guy
  • 1
    @AlgoRythm thanks man for that explanation! And I'm using Java
  • 1
    @Shigoogles Oh, good, I love Java. The example is actually written in Java
  • 1
    @nitaj96a Lol what? Why?
  • 0
    @nitaj96a ookay
  • 1
    @nitaj96a why did @RazorSh4rk stop you from ranting?
Add Comment