How to limit do while loop (571 Views)
Reply
Occasional Advisor
gpavl
Posts: 9
Registered: ‎11-08-2013
Message 1 of 6 (571 Views)
Accepted Solution

How to limit do while loop

I have a do while which is checking for the state of the variable "WFState".

Can anybody help me how to break this loop if the variable for any reason did not reach that state.

The loop may become infinite.

This is a code I'm using:

// var Opx = "Opened";
temp2="Investigation in Progress";  //compare string 2


//set x to 0 x is the success flag
x=0;
do{
web_reg_save_param("WFState",
"LB/IC=; border-left: 0px;\">",
"RB/IC= ",
"Ord=5",
"Search=Body",
"RelFrameId=1",
"NotFound=warning",
LAST);
//Compare correlation value with charater string
temp = lr_eval_string(lr_eval_string("{WFState}"));

if (strcmp(temp,temp2)==0) {
x=9; //set flag to indicate success
}
}while (x == 0);    //do while flag is not set

Respected Contributor
Srihari_Amgen
Posts: 426
Registered: ‎11-25-2011
Message 2 of 6 (556 Views)

Re: How to limit do while loop

[ Edited ]

Hi Gpavi,

 

Below is a sample C program for your situation, Use it in your logic for exiting out of do...while loop based on a condition.

 

#include<stdio.h>
		#include<conio.h>
		void main()
		{
		  clrscr();
		  int iteration_number=0;
		  int x=0;
		  do
		  {
		    printf("\n I am in Iteration:%d",iteration_number);
		    iteration_number +=1;
		    if( iteration_number == 5)
		    {
		     printf("\n The While condition satisfied");
		     printf("\n Since the iteration count reached 5;\n I am exiting out of this do while loop");
		     break;
		    }
		  }
		  while(x==0);
		  // I will loop out only if value of x !=0
		  // But as per our program this condition will never be met
		  getch();
		 }

 Regards,

Srihari

Occasional Advisor
gpavl
Posts: 9
Registered: ‎11-08-2013
Message 3 of 6 (528 Views)

Re: How to limit do while loop

Hi Srihari,

Thank you for helping me.

I modified your program to meet my needs and simply inserted this peace of code into do...while loop:

 

temp2="true";  //compare string 2

 //set x to 0 x is the success flag
 x=0;
 do{

 web_reg_save_param("RunState",
  "LB/IC=bHasOpenChildren = \"",
  "RB/IC=\"",
  "Ord=1",
  "Search=Body",
  "RelFrameId=1",
  "NotFound=warning",
  LAST);

 

//....................Server call comes here

 

 

 temp = lr_eval_string(lr_eval_string("{RunState}"));
 iteration_number +=1;
 if(iteration_number == 500)
 {
  lr_output_message("\n Since the iteration count reached 500; \n I am exiting the loop;\n WS failed to create child  record");
  break;
 }

 if (strcmp(temp,temp2)==0) {
  x=9;    //set flag to indicate success
 }

 }while (x == 0);    //do while flag is not set

  lr_output_message("Loop conditions were sutisfied");

 

It breaks the loop if conditon is not sutisfied

 

Respected Contributor
Srihari_Amgen
Posts: 426
Registered: ‎11-25-2011
Message 4 of 6 (524 Views)

Re: How to limit do while loop

Hi Gpavl,

 

Glad to know that this logic helped you to resolve your issue.

 

Can you please select my answer as "report as solution" so that other people can understand that we have already resolved this issue.

 

Regards,

Srihari

Occasional Advisor
gpavl
Posts: 9
Registered: ‎11-08-2013
Message 5 of 6 (516 Views)

Re: How to limit do while loop

I do not know how to do this.

I cannot find this option "Report as a solution".

 

Respected Contributor
Srihari_Amgen
Posts: 426
Registered: ‎11-25-2011
Message 6 of 6 (509 Views)

Re: How to limit do while loop

Sorry it is "Accept as solution" you have already done that.

No Issues.

 

Regards,

Srihari 

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.