Quote (fideuu @ 12 Jan 2012 20:55)
ja haha xD

just that i need some help in swedish for this one.
Hittar ingen bra förklaring på loopar,
#include<iostream>
using std::cout;
int main()
{
int tal;
tal = 1;
while (tal <= 100)
{
cout << tal << "\n";
tal+=1;
}
detta är hur man ska göra enligt guiden jag läser m.m.
det finns en förklaring men förstår inte riktigt, om någon snäll pajk skullle kunna göra det lite klarare för mig vore det uppskattat.
First, you declare an integer named tal, and set the value of it = 1.
Then, you run through the code
Code
cout << tal << "\n";
tal+=1;
as long as
Code
while (tal <= 100)
is true.
Example: first time you get to the while loop, tal == 1, meaning that (tal <= 100) == true, further meaning that you execute the code inside the while. The inner code prints tal (which is == 1 now), and sets tal = tal+1;
Now the code checks whether (tal <= 100) is still == true - if it is true, it will once again execute the code inside the while loop, and continue to do so, until tal > 100.
If you're having problems seeing what your code does, I can really recommend you sitting down and going through it on a piece of paper with a pencil. You can spot a lot of mistakes and get a general understanding that way.
