Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
skip an iteration in a loop without using if condition...
10-12-2011, 03:31 PM
Post: #1
Exclamation skip an iteration in a loop without using if condition...

Dear friends,

Recently i had attend an interview and the interviewer ask me a question,

How will you skip a particular iteration from a loop in vb script without using the If condition checking inside the loop. i have no answer for this question and still searching for it.. is there anyone know..pls share it..


Thanks,
Shibin P
Find all posts by this user
Quote this message in a reply
10-12-2011, 04:49 PM
Post: #2
RE: skip an iteration in a loop without using if condition...
Shibin, Please don't create duplicate threads. We have deleted the other one.

As far as the answer is concerned (unless this is a trick question), one of the methods can be by putting this for loop in a function and making the lower and upper index as variables. So you can have something like

PHP Code:
Function loop_iteration(lower,upper)
...
End Function

if 
you wish to skip say nth iteration you can 

Call 
(lowern-1)
Call (n+1upper

Others - please contribute your solutions as well.

QTP Articles | QTP Training | QTP Jobs
Find all posts by this user
Quote this message in a reply
10-12-2011, 04:55 PM
Post: #3
RE: skip an iteration in a loop without using if condition...
Thanks for the reply... i hope this is something like writing a loop for 2 times by avoiding the iteration which is not required.. m not sure whether my interviewer want the same...

thanks again...

(10-12-2011 04:49 PM)Ankur Wrote:  Shibin, Please don't create duplicate threads. We have deleted the other one.

As far as the answer is concerned (unless this is a trick question), one of the methods can be by putting this for loop in a function and making the lower and upper index as variables. So you can have something like

PHP Code:
Function loop_iteration(lower,upper)
...
End Function

if 
you wish to skip say nth iteration you can 

Call 
(lowern-1)
Call (n+1upper

Others - please contribute your solutions as well.
Find all posts by this user
Quote this message in a reply
10-13-2011, 12:46 PM
Post: #4
RE: skip an iteration in a loop without using if condition...
Any new reply?????
Find all posts by this user
Quote this message in a reply
10-13-2011, 08:50 PM (This post was last modified: 10-13-2011 08:53 PM by vIns.)
Post: #5
RE: skip an iteration in a loop without using if condition...
Sorry if my reply is so stupid....

if the requirement is not to use 'IF' and 2 for loops...

i will do something like this

Code:
For iterationNo =1 to 100
      Select Case iterationNo
        Case N    ' condition to be skipped
                'Skipping
        Case Else
                ' continues
     End Select
Next

~vIns~
Find all posts by this user
Quote this message in a reply
10-13-2011, 09:49 PM
Post: #6
RE: skip an iteration in a loop without using if condition...
Dear friend ,

Many thanks for your reply... i m not sure but most probably u may be correct, because may be my interviewer was checking my outbox thinking/analytical skill...

thank you so much...

(10-13-2011 08:50 PM)vIns Wrote:  Sorry if my reply is so stupid....

if the requirement is not to use 'IF' and 2 for loops...

i will do something like this

Code:
For iterationNo =1 to 100
      Select Case iterationNo
        Case N    ' condition to be skipped
                'Skipping
        Case Else
                ' continues
     End Select
Next
Find all posts by this user
Quote this message in a reply
12-13-2011, 10:32 AM
Post: #7
RE: skip an iteration in a loop without using if condition...
how to make maximum number and minimum number function in QTP
Find all posts by this user
Quote this message in a reply
12-13-2011, 04:31 PM
Post: #8
RE: skip an iteration in a loop without using if condition...
ExitActionIteration
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)