Is there a way to run a while() loop for a limited time only, and then break away from it?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Is there a way to run a while() loop for a limited time only, and then break away from it?

ソリューションへジャンプ
2,487件の閲覧回数
admin
Specialist II

Hi. I'm familiar with the operation of the while() loop. I would like to know if it is possible to run a while() loop for only a few seconds (3 seconds for example), and then break away from it and go down to the next instruction? 

 

For example, in the code below:

while (sensor_value > 55)

  {

      ........ //operation here

  }

motor_stop();

 

Is it possible for the program to run the while() loop for only 3 seconds, and then breaks away from it regardless of the sensor_value, and goes down straight to the motor_stop() function?

 

Thx 

Message Edited by Cryptical on 2009-04-13 10:37 AM
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,397件の閲覧回数
J2MEJediMaster
Specialist I

Check out the break statement. Specifically, within your loop code you would write:

 

while (sensor_value > 55)

  {

      ........ //operation here

 

   if (time_interval >  THREE_SECONDS)

      break;

 

  }

motor_stop();

 

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,398件の閲覧回数
J2MEJediMaster
Specialist I

Check out the break statement. Specifically, within your loop code you would write:

 

while (sensor_value > 55)

  {

      ........ //operation here

 

   if (time_interval >  THREE_SECONDS)

      break;

 

  }

motor_stop();

 

 

0 件の賞賛
返信
1,397件の閲覧回数
admin
Specialist II

J2MEJediMaster wrote:

Check out the break statement. Specifically, within your loop code you would write:

 

while (sensor_value > 55)

  {

      ........ //operation here

 

   if (time_interval >  THREE_SECONDS)

      break;

 

  }

motor_stop();

 

 


 

Thx Jedi. I used your method and it helped. Cheers :smileyhappy:
0 件の賞賛
返信