1

I am using selenium concurrently element checking using timer in c#. If element found the call back will call then I need to continue the for loop.
This is my code, it is not working. Any Suggestions?

for (i = 0; i < list.length(); i++) {
    //statement
    mycallback((s) => { if(s) continue; }); // continue here
    //statement
}
Yonlif
  • 1,770
  • 1
  • 13
  • 31
lava
  • 6,020
  • 2
  • 31
  • 28
  • you want to continue `for` loop from the beginning in some cases and continue the trace in some other cases? – Majid Roustaei Jun 01 '20 at 16:47
  • can you elaborate .i coudn't get it .in this for loop . i used time based approach . so it is difficult .so i use event based . so when i detect some element using callback .if that callback occured the process .will stop and continue to the next index .but this call back working but the loop stoping or continue not working . – lava Jun 01 '20 at 17:11
  • Is this Java or C#? It can't be both... – Yonlif Jun 01 '20 at 17:13
  • c# .I can't continue the loop .i thought both have same approach.i used system.timer class and thread .in java also this approach possible . – lava Jun 01 '20 at 17:16

1 Answers1

0

in C# you can use labels to go where you want. they transfer the program control directly to a labeled statement

look at the snippet below:

for (i = 0; i < list.length(); i++) {
    //statement

    mycallback((s) => { if(s) goto myLabel; });

    // continue here
    myLabel: // parts of your code

    //statement
}

it is not recommended though that could be useful in some cases.

more info about this syntax: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/goto

more discussion about using labels: Does anyone still use [goto] in C# and if so why?

Majid Roustaei
  • 1,556
  • 1
  • 20
  • 39
  • Thank you for your replay .it showing compile error .showing invalid jump – lava Jun 02 '20 at 11:57
  • It depends on where you put the `label`. as an error example: https://stackoverflow.com/questions/18535283/why-cant-i-add-a-goto-label-at-the-end-of-a-method – Majid Roustaei Jun 02 '20 at 12:14
  • i just add the label outside the callback and goto it works.other wise it showing invalid jump – lava Jun 02 '20 at 15:25