+ 1
How to use for loop
So I have to use a for loop in a situation where a guy gets paid a const amount per hour, for 3 weeks And the program should calc the total income during the loop
2 Answers
+ 2
Hey you don't need a for loop for that :))
int money;
cin>>money;
int totalHours = 3 * 7 * 24;
int totalMoney = money * totalHours;
cout << totalMoney;
0
A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. For example, when you are displaying number from 1 to 100 you may want set the value of a variable to 1 and display it 100 times, increasing its value by 1 on each loop iteration.
for(initialization; condition ; increment/decrement)
{
C++ statement(s);
}
First step:Â In for loop, initialization happens first and only once, which means that the initialization part of for loop only executes once.
Second step:Â Condition in for loop is evaluated on each loop iteration, if the condition is true then the statements inside for for loop body gets executed. Once the condition returns false, the statements in for loop does not execute and the control gets transferred to the next statement in the program after for loop.
Third step:Â After every execution of for loopâs body, the increment/decrement part of for loop executes that updates the loop counter.
Fourth step:Â After third step, condition is re-evaluated.



