0

I need help to understand for loops

4th Oct 2021, 6:38 PM
Nouman Ashraf
9 odpowiedzi
+ 2
Nouman Ashraf see statement am telling in c cpp and java python loop is little bit different you have not mentioned language so i consider you know c cpp . 1st part 2nd. 3rd part for(int i=0; i<10; i++) { cout<<i<<endl; } See here in condition i have written i<10 and i starting from zero so how many times condition can be true see i<10 //when( i) initial zero means 0<10here this is true so print statement will execute then after condition i have written increment so i will be increased by 1 Now i value is 1 i<10 = 1<10 condition true then print statement will execute Then i++-- > 2 2<10 Condition true again rest of code will execute ....... ......... 9<10 condition true 10<10 here condition false so rest of statement will not execute for(i=5; i<7;i++) 5<7 true then statement then increment Then again condition then statement then increment ...... 6<7 7<7 so see how many times here loop working total two times
4th Oct 2021, 7:06 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Nouman Ashraf first write for loop and see the statement which u have written inside bracket Initialisation ,condition and increment/decrement First initialisation part will be execute the statement then condition then increment Then again condition then statement then increment decrement. Again condition then statement then increment decrement Same process will be repeat till until your condition failed . So dry run means to analyse your program output and flow without running code. Note: for better understanding you can refer online tutorials
4th Oct 2021, 6:50 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Dry run is best way to understand things
4th Oct 2021, 6:44 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
What is a dry run
4th Oct 2021, 6:45 PM
Nouman Ashraf
0
Google has nearly two million results for "for loops" and over twenty million for "for loop" ...
4th Oct 2021, 6:47 PM
Simon Sauter
Simon Sauter - avatar
0
But how do should i teach myself to use the right condition and statement and increment
4th Oct 2021, 6:56 PM
Nouman Ashraf
0
Everyone has already explained very well. But let me tell you that you are gonna use "i" as counter variable in almost all loops which you will make in your future.
5th Oct 2021, 7:04 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar