TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Roy S
NA
650
0
Making custom loops?
Mar 7 2011 5:47 PM
I have a certain nesting of loops, something similar to this:
for
(
int
i = 0; i < 10; i++)
{
for
(
int
j = 0; j < 10; j++)
{
for
(
int
k = i + j; ;k += i + j)
{
doing stuff here...
}
}
}
Returning all over my project. the only thing changing is what I do inside the loops.
Is there a way to put the whole loop thing somewhere else and just tell what needs to be done in the loop? I was thinking of using something like this:
public void
Main()
{
CostumLoop(i =>
{
doing stuff here...
});
}
public void
CostumLoop(
Action
<
int
> doStuff)
{
for
(
int
i = 0; i < 10; i++)
{
for
(
int
j = 0; j < 10; j++)
{
for
(
int
k = i + j; ;k += i + j)
{
doStuff(k);
}
}
}
}
But then I can't use any breaks or continue etc (which I actually need)... Is there maybe a way of telling that the break in de lambda is going to executed inside a loop and that it shouldn't give an error?
Any ideas?
Reply
Answers (
8
)
Using OLEDB to write to excel file.. problems
LAN Network Discovery