how to loop a code a certain amount of time

For example a code a that reads the value of an L.D.R and then it executes a code to give it outputs.
Is it possible to make it run 60 times exactly.
I know that while(1) is infinite but is there a way to do this
1
2
3
4
5
6
7
8
size_t i = 0;
while (i < 60) {
  // your code here



i++;
}
why did you use a while loop instead of a for loop?
or you can use for:
1
2
3
for(int i = 0 ; i < 60 ; i++){
//your code
}


the for loop goes this way:
1-initialize (the int i = 0 ) once
2-check the if statement (the i<60 part)
a-if it was true : go 3-
b-if it was false: jump out
3-run your code
4-do last part(i++)
5-go 2-

note: you can use any other type instead of int, even you dont need to use same var for 3 part, you can use difrent ones
Topic archived. No new replies allowed.