avoid repeating a statement
Oct 24, 2014 at 12:22pm
lets say I want to repeat this
1 2 3 4 5 6 7
|
for(i=0;i<16;i++)
...
...
for(i=0;i<16;i++)
...
for(i=0;i<16;i++)...
for(i=0;i<16;i++)
|
but typing
for(i=0;i<16;i++)
every time is kind of lengthy...
isn't there a
shortcut???
Oct 24, 2014 at 12:42pm
Solution 1:
Combine loops into one
Solution 2:
Move loop with its body inside separate function
Nothing more can be said without knowing context of these loops and what are they doing.
Oct 26, 2014 at 9:58am
cant we create a variable or something like that???
Oct 26, 2014 at 10:00am
cant we create a variable or something like that??? |
Depending on loop context and content.
Oct 26, 2014 at 2:59pm
1 2 3 4
|
for (int j=0; j<n; ++j) {
for (i=0; i<16; i++)
...
}
|
Oct 26, 2014 at 3:56pm
Use an editor abbreviation (check the documentation for your editor.)
For instance (vim,allman) :ab forl for( int i=0; i<N; ++i ) <CR>{<CR>
Topic archived. No new replies allowed.